【问题标题】:Facebook App: post to page now failing with "An unknown error has occurred" / OAuthExceptionFacebook 应用程序:发布到页面现在失败,出现“发生未知错误”/OAuthException
【发布时间】:2012-10-01 22:48:56
【问题描述】:

我有一个将每日状态发布到页面墙上的应用程序,状态作为应用程序发布(请参阅http://facebook.com/fragrantheart)。我的应用程序是“Fragrant Heart Daily Meditations”,正如您所见,多年来一直很高兴发布。 但是,现在,当它发布时,我得到了错误:

 [message] => An unknown error has occurred.
 [type] => OAuthException
 [code] => 1

这是我在服务器上运行的代码(PHP api):

$facebook = new Facebook(array('appId'=>'148279321865482', 'secret'=>'XXXXXX', 'cookie'=>false));
$target_id = '124924677541618'; // Fragrant Heart Meditation Page
$facebook->api("/{$target_id}/feed", 'POST', array('message'=>$msg));

根据我的阅读,不需要 access_token,因为该页面已授予我的应用 publish_stream 权限。

最近发生了什么变化会导致此错误?代码没有改变。

我还尝试了服务器端身份验证流程来获取访问令牌,当通过调试器运行该令牌时,我得到:

App ID:  148279321865482 : Fragrant Heart Daily Meditations
User ID: 100001170589484 : Elisabeth Blaikie
Issued:  1289470487 (over a year ago)
Expires: Never
Valid:   True
Origin:  Web
Scopes:  create_note manage_pages offline_access photo_upload publish_actions publish_stream share_item status_update video_upload

但是当像这样使用访问令牌时:(显然,YYYYYY被实际令牌替换):

$facebook = new Facebook(array('appId'=>'148279321865482', 'secret'=>'XXXXXX', 'cookie'=>false));
$target_id = '124924677541618'; // Fragrant Heart Meditation Page
$facebook->api("/{$target_id}/feed", 'POST', array('message'=>$msg, 'access_token'=>'YYYYYYY'));

我得到错误:

[message] => Invalid OAuth access token.
[type] => OAuthException
[code] => 190

感谢您的帮助。

【问题讨论】:

    标签: facebook-graph-api oauth facebook-php-sdk facebook-apps


    【解决方案1】:

    哈哈 - 所以原来的问题实际上是缺少 access_token;但是,当我将 access_code 粘贴到我的代码中时,我错误地复制了我的访问密钥;因此“无效的 OAuth 访问令牌”。哦!

    因此对于处于相同情况的其他任何人(从 PHP 服务器自动发布到您自己的页面),正确的代码是

    $facebook = new Facebook(array('appId'=>'YOUR APP ID', 'secret'=>'YOUR APP SECRET', 'cookie'=>false));
    $target_id = 'YOUR PAGE ID'; 
    $facebook->api("/{$target_id}/feed", 'POST', array('message'=>'YOUR MESSAGE', 'access_token'=>'YYYYYYY'));
    

    要获得永久访问令牌,请按照http://developers.facebook.com/docs/authentication/server-side/ 中的步骤,特别是步骤 1 和 4:

    以您要发布到的页面的所有者身份登录。前往

    https://www.facebook.com/dialog/oauth?
        client_id=YOUR_APP_ID
       &redirect_uri=YOUR_REDIRECT_URI
       &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
       &state=SOME_ARBITRARY_BUT_UNIQUE_STRING
    

    COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES 应该是 publish_stream,以及您需要的任何其他权限。 接受请求,该请求将重定向回 YOUR_REDIRECT_URI(必须与您的应用设置中的域相同) 从重定向 URI 复制 CODE 并转到

    https://graph.facebook.com/oauth/access_token?
        client_id=YOUR_APP_ID
       &redirect_uri=YOUR_REDIRECT_URI
       &client_secret=YOUR_APP_SECRET
       &code=CODE_GENERATED_BY_FACEBOOK
    

    访问令牌将位于页面正文中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多