作为页面管理员发布 Graph Api 错误
我正在使用 graph api 在 php 中开发一个应用程序。 因此,我必须以管理员身份将消息发布到 Facebook 页面。我按照以下步骤操作: How to post to Facebookpage as通过 API (Php SDK) 进行管理? . 它运行良好几次,但现在返回此错误: PHP 致命错误:未捕获的 GraphMethodException:不支持的发布请求。\n 在第 453 行的 /home/redmarv/public_html/owl-test/facebook.php 中抛出,
但找不到问题出在哪里。即使使用谷歌或搜索其他帖子。 但我不明白为什么它有效几次然后就不行了。 无需改变任何东西。
实际上我使用这段代码:
include_once "fbmain.php";
echo 'Hi ' . $uid . '<br />';
$fb_accounts = $facebook->api('/me/accounts');
$access_token = $fb_accounts['data'][1]['access_token'];
echo 'Access Token= ' . $access_token;
$facebook->api('/page_id/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid, 'access_token'=>$access_token, 'cb'=>''));
包含的 fbmain.php 执行会话控制并创建 $facebook 对象。 抱歉我的英语不好,谢谢。
I'm developing an application in php using graph api.
So, I have to post messages to a Facebook page as admin. I followed this: How to post to Facebookpage as admin via API (Php SDK)? .
It worked well a couple of time, but now it returns this error:
PHP Fatal error: Uncaught GraphMethodException: Unsupported post request.\n thrown in /home/redmarv/public_html/owl-test/facebook.php on line 453
But can't find where the problem is. Even with google or search other posts right there.
But I can't understand why it works a couple of time and then no.
Without changing anything.
Actually I use this code:
include_once "fbmain.php";
echo 'Hi ' . $uid . '<br />';
$fb_accounts = $facebook->api('/me/accounts');
$access_token = $fb_accounts['data'][1]['access_token'];
echo 'Access Token= ' . $access_token;
$facebook->api('/page_id/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid, 'access_token'=>$access_token, 'cb'=>''));
The included fbmain.php does the session contro and create the $facebook object.
Sorry for my bad English and thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果用户在发出图形请求时未登录您的应用程序,您将收到上述错误。
我假设“fbmain.php”中的代码处理用户身份验证并返回 $uid,但如果您在点击此脚本之前尚未登录,则包含“fbmain.php”之后的代码可能会在之前运行Facebook 执行登录重定向。
尝试在使用 $uid 之前进行检查以确保它确实包含有效的整数。
If a user isn't logged into your app while making graph requests, you'll get the error you describe above.
I'm assuming the code in 'fbmain.php' handles authenticating the user and returning the $uid, but if you're already not logged in before hitting this script, the code after the include 'fbmain.php' is probably running before Facebook does the login redirect.
Try including a check to make sure $uid actually contains a valid integer before using it.
对于其他有同样问题的人,我会摆脱它。
解决方案非常简单,如果您想将其作为页面本身发布在页面墙上,则必须更改此设置:
这样:
这非常简单,如果您是要发布到您的页面(使用它的access_token)墙(即“/me/feed”)。
希望这会对某人有所帮助!
For other that will have the same problem, I get rid of it.
The solution was pretty simple, if you want to post on your page wall as the page itself, you have to change this:
With this:
This is very simple, if you are the page (using it's access_token) you want to post to your wall (so to '/me/feed').
Hoping this will help someone!