作为页面管理员发布 Graph Api 错误

发布于 2024-10-09 15:17:03 字数 906 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人间☆小暴躁 2024-10-16 15:17:03

如果用户在发出图形请求时未登录您的应用程序,您将收到上述错误。

我假设“fbmain.php”中的代码处理用户身份验证并返回 $uid,但如果您在点击此脚本之前尚未登录,则包含“fbmain.php”之后的代码可能会在之前运行Facebook 执行登录重定向。

尝试在使用 $uid 之前进行检查以确保它确实包含有效的整数。

include_once "fbmain.php";

if(is_int($uid) && $uid > 0) {
  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'=>''));
} else {
  // wait for facebook to redirect page to loginUrl or do something else
}

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.

include_once "fbmain.php";

if(is_int($uid) && $uid > 0) {
  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'=>''));
} else {
  // wait for facebook to redirect page to loginUrl or do something else
}
随风而去 2024-10-16 15:17:03

对于其他有同样问题的人,我会摆脱它。
解决方案非常简单,如果您想将其作为页面本身发布在页面墙上,则必须更改此设置:

$facebook->api('/page_id/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid,  'access_token'=>$access_token, 'cb'=>''));

这样:

$facebook->api('/me/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid,  'access_token'=>$access_token, 'cb'=>''));

这非常简单,如果您是要发布到您的页面(使用它的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:

$facebook->api('/page_id/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid,  'access_token'=>$access_token, 'cb'=>''));

With this:

$facebook->api('/me/feed', 'post', array('message'=>'OWL F TOOLS N TEST by: '.$uid,  'access_token'=>$access_token, 'cb'=>''));

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文