Facebook Graph API 返回 false

发布于 2024-10-17 20:43:09 字数 356 浏览 2 评论 0原文

我正在处理好友请求。当用户发送好友请求时,我会收到 request_id 作为响应。但是,当我按如下方式使用此 request_id ( XXXX) 时:

https://graph.facebook.com/XXXX/?access_token=YYYYYYYYY

它返回:

false

access_token 似乎是正确的(此处使用的仅作为示例),我我错过了什么? 是什么意思?如何获取 JSON 对象作为返回数据?

I am working with friend requests. When the user sends a friend request, I get a request_id as a response. However, when i use this request_id ( XXXX) as follows:

https://graph.facebook.com/XXXX/?access_token=YYYYYYYYY

it returns:

false

the access_token seems to be the right one( the one used here is for example only), am i missing something ? what does false mean? how do i get the JSON object as the return data?

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

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

发布评论

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

评论(2

怕倦 2024-10-24 20:43:09

看来您的页面配置有任何限制。我猜想有国家或年龄的限制。

删除FB页面中的条件并重试。

更新:

只是我的猜测,但我认为在限制的情况下返回 false 的原因是因为 FB 无法验证请求是否符合页面限制。 解决了这个问题

我使用 OAuth 2.0 OAuth 2.0 的 Facebook 文档

,这里有一些代码来解决这个问题更简单:

FILE 1:

require_once( 'oauth2callback/index.php' );

// Get likes from FB using auth
$likes = do_auth_FB( '[Object name]' );
echo 'Likes en Facebook: ' . $likes . '<br/>';

FILE 2: (oauth2callback/index.php)

function do_auth_FB( $objectName) {

    // Setting required variables
    $fbAppID = '[App ID]';
    $fbSecret = '[App secret]';
    $redirectURI = '[URL to redirect]';
    $objectName = '[Object name]';

    // Getting code var
    $code = $_GET["code"];

    // Calling for code
    if( empty( $code ) ) {
        $urlcode = 'http://www.facebook.com/dialog/oauth?'
       . 'client_id=' . $fbAppID . '&redirect_uri=' . urlencode( $redirectURI )
       . '&client_secret=' . $fbSecret;

        echo "<script> top.location.href='" . $urlcode . "'</script>";
    }

    // Calling for token
    $urlToken = 'https://graph.facebook.com/oauth/access_token?'
       . 'client_id=' . $fbAppID . '&redirect_uri=' . urlencode( $redirectURI )
       . '&client_secret=' . $fbSecret . '&code=' . $code;

    $response = file_get_contents( $urlToken );
    $outputResponse = null;
    parse_str( $response, $outputResponse );

    // Calling for the required object
    $graph_url = 'https://graph.facebook.com/' . $objectName . '?access_token='
       . $outputResponse["access_token"];

    $objectStream = json_decode( file_get_contents( $graph_url ) );

    return $objectStream->likes;
}

在示例中仅返回喜欢的页面

Seems like you have any restriction in your page config. I guess any restriction by country or by age.

Remove the condition in the FB page and try again.

UPDATE:

Is just my guessing but I assume that the reason because it return false in case of restrictions is because FB could not verify is the request complies with the page restrictions. I solve the problem using OAuth 2.0

Facebook docs for OAuth 2.0

And here some code to make the life easier:

FILE 1:

require_once( 'oauth2callback/index.php' );

// Get likes from FB using auth
$likes = do_auth_FB( '[Object name]' );
echo 'Likes en Facebook: ' . $likes . '<br/>';

FILE 2: (oauth2callback/index.php)

function do_auth_FB( $objectName) {

    // Setting required variables
    $fbAppID = '[App ID]';
    $fbSecret = '[App secret]';
    $redirectURI = '[URL to redirect]';
    $objectName = '[Object name]';

    // Getting code var
    $code = $_GET["code"];

    // Calling for code
    if( empty( $code ) ) {
        $urlcode = 'http://www.facebook.com/dialog/oauth?'
       . 'client_id=' . $fbAppID . '&redirect_uri=' . urlencode( $redirectURI )
       . '&client_secret=' . $fbSecret;

        echo "<script> top.location.href='" . $urlcode . "'</script>";
    }

    // Calling for token
    $urlToken = 'https://graph.facebook.com/oauth/access_token?'
       . 'client_id=' . $fbAppID . '&redirect_uri=' . urlencode( $redirectURI )
       . '&client_secret=' . $fbSecret . '&code=' . $code;

    $response = file_get_contents( $urlToken );
    $outputResponse = null;
    parse_str( $response, $outputResponse );

    // Calling for the required object
    $graph_url = 'https://graph.facebook.com/' . $objectName . '?access_token='
       . $outputResponse["access_token"];

    $objectStream = json_decode( file_get_contents( $graph_url ) );

    return $objectStream->likes;
}

In the example only returns the page likes

鸢与 2024-10-24 20:43:09

尝试不使用最后一个斜杠:

https://graph.facebook.com/XXXX?access_token=YYYYYYYYY

还可以使用应用程序访问令牌进行尝试。

Try it without the last slash:

https://graph.facebook.com/XXXX?access_token=YYYYYYYYY

Also try it with an application access token.

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