Facebook PHP API 订阅问题

发布于 2024-12-08 17:42:01 字数 1010 浏览 4 评论 0原文

我正在尝试按照此处所述使用 Facebook 的实时更新。我正在使用 PHP SDK。我已经拥有一个可用于具有以下权限的其他功能的访问令牌:user_checkins、publish_stream、offline_access。

尝试添加订阅时,我从 Facebook SDK 收到以下错误。

致命错误:未捕获 OAuthException:(#15) 必须使用应用程序 access_token 调用此方法

我正在使用的代码如下。所有变量均设置正确。有什么想法吗?

    $callback_url = plugins_url('fb_callback.php',__FILE__);
    $config = array('appId' => $app_id,
                    'secret' => $app_secret,
                     );
    $facebook = new Facebook($config);
    $token = fb_get_access_token();
    $facebook->setAccessToken($token);
    $ret_obj = $facebook->api($app_id . '/subscriptions', 'POST',
                array('callback_url' => $callback_url,
                      'object' => 'checkin',
                      'verify_token' => 'a390jkl091091j908j',
                      'fields' => 'id'
                      ));

I'm trying to use Facebook's realtime updates as described here. I'm using the PHP SDK. I already have an access token that works for other functions with these permissions: usser_checkins,publish_stream,offline_access.

When trying to add the subscription I receive the following error from the Facebook SDK.

Fatal error: Uncaught OAuthException: (#15) This method must be called with an app access_token

The code I am using is below. All the variables are set correctly. Any ideas?

    $callback_url = plugins_url('fb_callback.php',__FILE__);
    $config = array('appId' => $app_id,
                    'secret' => $app_secret,
                     );
    $facebook = new Facebook($config);
    $token = fb_get_access_token();
    $facebook->setAccessToken($token);
    $ret_obj = $facebook->api($app_id . '/subscriptions', 'POST',
                array('callback_url' => $callback_url,
                      'object' => 'checkin',
                      'verify_token' => 'a390jkl091091j908j',
                      'fields' => 'id'
                      ));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

静若繁花 2024-12-15 17:42:01

我用示例代码写了一篇文章,其中包含此问题的解决方案:

http://marcneuwirth.com/blog/2011/12/08/facebook-real-time-updates/

希望有帮助。

I wrote a post with my solution for this problem with example code:

http://marcneuwirth.com/blog/2011/12/08/facebook-real-time-updates/

Hopefully that helps.

我有类似的问题。不确定是否和你的一样。但是,只有当且仅当请求 URI 的查询字符串中没有“范围”时,应用访问令牌才会按预期返回。换句话说,它需要准确无误:

https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

如果与上面不同,它将返回用户访问令牌,即使使用&grant_type=client_credentials

I had a similar issue. Not sure if it's the same as yours. But, the app access token is only returned as expected if, and only if, the request URI do not have the "scope" on the querystring. In other words, it need to be exactly:

https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

If it's different from the above, it will return the user access token, even with the &grant_type=client_credentials

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