Facebook OAuthException:验证应用程序时出错

发布于 2024-11-06 21:13:58 字数 1241 浏览 0 评论 0原文

我有一个简单的 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 调用做错了,但我似乎无法弄清楚。这两天我一直在纠结这个问题。有人可以帮忙吗! :(

I have a simple PHP page that is going to be used to post a message to my own wall.

I've obtained an offline_access token that has "read_stream" and "publish_stream" permissions.

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;
}

When I run this, I get "OAuthException: Error validating application".

I confirmed that my offline token is good. When I go to https://graph.facebook.com/me?access_token=[MY_OFFLINE_TOKEN], it returns my public profile in JSON format correctly.

So, I'm thinking I'm doing something wrong with the API call somewhere but for the life of me I can't seem to figure it out. I've been wrestling with this issue for the last two days. Could someone please help! :(

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

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

发布评论

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

评论(1

嗼ふ静 2024-11-13 21:13:58

您这里没有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;
}

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

You don't have APP ID here. And make calls like this:

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;
}

Untested, but should work. Let me know if it doesn't.

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