2011-02-16 144 views
5

我正在处理好友请求。当用户发送好友请求时,我得到一个request_id作为回应。然而,当我使用这个REQUEST_ID(XXXX),如下所示:Facebook Graph API返回false

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

返回:

false 

的access_token似乎是正确的(这里所使用的是例如只),我错过了什么? false是什么意思?我如何获取JSON对象作为返回数据?

回答

3

尝试没有最后的斜线:

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

而且与应用程序的访问令牌尝试。

+0

我在最后尝试没有'/',但它仍然给出'假'。你能否让我知道什么是'应用程序访问令牌'?我使用的access_token是应用程序在用户身份验证时获得的。 – lugbug 2011-02-16 23:29:50

+0

是的,有用。 request_id要求应用程序访问令牌针对用户访问令牌。应用程序访问令牌也被记录为“请求对话框”下的“签名应用程序秘密”。 – lugbug 2011-02-17 00:17:49

5

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

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

UPDATE:

只是我的猜测,但我认为,因为它在限制的情况下返回false的原因是因为FB无法验证是请求与页面限制的规定。我解决了使用OAuth 2.0

Facebook docs for OAuth 2.0

这里的一些代码,使生活更轻松的问题:

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

在该示例中只返回页面赞