【问题标题】:Facebook Graph Api - Posting to page without loggingFacebook Graph Api - 在不记录的情况下发布到页面
【发布时间】:2012-10-03 12:52:09
【问题描述】:

我正在尝试创建一个脚本,该脚本无需登录用户即可在 Facebook 页面上发布状态更新。当用户授予应用程序一次时,我的应用程序和页面都有 access_token ;但我总是得到错误

Fatal error:  Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action

尽管我已授予 ma​​nage_pagespublish_stream 权限。 另外,如果我将 access_token 用于页面,我会收到错误

Fatal error:  Uncaught OAuthException: Error validating access token: The session is invalid because the user logged out.

这是我使用的代码。

$facebook = new Facebook(array(
        'appId'  => 'XXX',
        'secret' => 'XXXXXXXXXXX'
));

$post = array(
    'message'   => 'Message to user'/*,
     access_token = "XXXXXXXX"*/
);
$feed = '/[PAGE_ID]/feed';

$post_id = $facebook->api($feed, "post", $post);

谢谢。

编辑:

我终于设法在该用户断开连接时在用户页面上发布状态更新,我必须通过服务器端身份验证方法生成 access_token。

【问题讨论】:

  • 确保您有 2 个令牌,用户身份验证令牌和页面身份验证令牌。

标签: php facebook facebook-graph-api facebook-page


【解决方案1】:

下面是一个关于如何在页面上发布 FB 的小代码:

你需要:

  • Your_authToken_for_User

  • 列表项

saved_fb_Page_Token

 $facebook = $facebook = new Facebook(array(
                'appId' => $fbAppId,
                'secret' => $fbAppSecret,
                'cookie' => true,
            ));
    $facebook->setAccessToken("Your_authToken_for_User");

   //Now your FB instance is authenticated.

    $pages= $facebook->api('/me/accounts'); //use the current authenticated FB instance to grab Pages. If you already know your page ID , skip this.

   //Assuming you have a pageid in $page_id,(the $page_id can be grabbed from the $pages array).

    $attachment = array(
                'access_token' => $saved_fb_Page_Token,
                'message' => "foo",
                'name' => "Bar",
                'link' => "http://foo.bar",
                'description' => "barfoo",
                'picture' => "an image url here",
            );

     $facebook->api('/' . $page_id . '/feed', 'POST', $attachment);//post to fb page

【讨论】:

  • 感谢您的回答,我设法将其发布到页面。但是,一旦用户注销,我就会面临“会话无效”错误。另外我相信用户身份验证令牌的有效期最长为 60 天。由于该应用程序已通过帐户验证,是否有任何方法可以绕过用户身份验证过程?或者有什么方法可以获得永久用户身份验证令牌?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
相关资源
最近更新 更多