Facebook Graph API返回false

lug*_*bug 5 facebook facebook-graph-api

我正在处理好友请求.当用户发送好友请求时,我得到一个request_id作为回复.但是,当我使用此request_id(XXXX)时,如下所示:

https://graph.facebook.com/XXXX/?access_token=YYYYYYYYY
Run Code Online (Sandbox Code Playgroud)

它返回:

false
Run Code Online (Sandbox Code Playgroud)

的access_token似乎是正确的(这里使用的是一个例如只),我失去了什么?虚假是什么意思?我如何获得JSON对象作为返回数据?

Cra*_*ess 5

好像你的页面配置有任何限制.我想任何国家或年龄的限制.

删除FB页面中的条件,然后重试.

更新:

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

Facebook为OAuth 2.0提供文档

这里有一些代码可以让生活更轻松:

文件1:

require_once( 'oauth2callback/index.php' );

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

文件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;
}
Run Code Online (Sandbox Code Playgroud)

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


ifa*_*our 3

尝试不加最后一个斜杠:

https://graph.facebook.com/XXXX?access_token=YYYYYYYYY
Run Code Online (Sandbox Code Playgroud)

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