【问题标题】:Facebook OAuthException: Error validating applicationFacebook OAuthException:验证应用程序时出错
【发布时间】:2011-05-11 00:34:23
【问题描述】:

我有一个简单的 PHP 页面,将用于在我自己的墙上发布消息。

我获得了一个具有“read_stream”和“publish_stream”权限的offline_access 令牌。

define('FB_APIKEY', 'MY_APP_KEY');

define('FB_SECRET', 'MY_APP_SECRET');

define('FB_SESSION', 'MY_OFFLINE_TOKEN');

require_once('facebook.php');

try {
    $facebook = new Facebook(FB_APIKEY, FB_SECRET);

    $facebook->api_client->session_key = FB_SESSION;

    $attachment = array(
        'message' => 'some meesgae',
        'name' => 'This is my demo Facebook application!',
        'caption' => "Caption of the Post",
        'link' => 'mylink.com',
        'description' => 'this is a description',
        'actions' => array(array(
                     'name' => 'Get Search', 
                     'link' => 'google.com'
                  ))
    );

    $result = $facebook->api('/me/feed?access_token=' . FB_SESSION, 
              'post', 
              $attachment);

     var_dump($result);

} catch(Exception $e) {
     echo $e;
}

当我运行它时,我得到“OAuthException:验证应用程序错误”。

我确认我的离线令牌是好的。当我转到 https://graph.facebook.com/me?access_token=[MY_OFFLINE_TOKEN] 时,它会以 JSON 格式正确返回我的公开个人资料。

所以,我认为我在某个地方的 API 调用做错了,但对于我的生活,我似乎无法弄清楚。这两天我一直在纠结这个问题。有人可以帮忙吗! :(

【问题讨论】:

    标签: facebook facebook-graph-api


    【解决方案1】:

    这里没有APP ID。并像这样拨打电话:

    require_once('facebook.php');
    
    $facebook = new Facebook( array(
        'appId'  => 'APP_ID',
        'secret' => 'APP_SECRET',
        'cookie' => true
    ));
    
    try {
        $attachment = array(
            'message' => 'some meesgae',
            'name' => 'This is my demo Facebook application!',
            'caption' => "Caption of the Post",
            'link' => 'mylink.com',
            'description' => 'this is a description',
            'actions' => array(array(
                'name' => 'Get Search', 
                'link' => 'google.com'
                ))
        );
    
        $attachment['access_token'] = $offline_access_token; // add it to the array
    
        $result = $facebook->api('/me/feed', 'POST', $attachment );
    
        var_dump($result);
    
    } catch(Exception $e) {
        // error_log( $e ); // should use something like this when in production
        echo $e;
    }
    

    未经测试,但应该可以工作。如果没有,请告诉我。

    【讨论】:

    • 你知道如何以页面的名义发帖吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多