try{
$response = $fb->sendRequest('GET', '/1317727711586522', array(
'fields' => 'id,name,picture'
), $access_token);
}catch(Facebook\Exceptions\FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(Facebook\Exceptions\FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;}
$usersData=$response->getDecodedBody();
$usersName=$usersData['name'];
$usersId=$usersData['id'];
$usersPicture=$usersData['picture']['data']['url'];
一切正常,Graph完全没有错误。但是当我从我的数据库中列出用户的Facebook ID时,它会返回错误:Graph returned an error: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
。以下是我执行此操作的代码:
$queryForUsers="SELECT * FROM $tabela";
$resultForUsers=$mysqli->query($queryForUsers);
//var_dump($resultForUsers);
$fb = new Facebook\Facebook([
'app_id' => $apid,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.5',
]);
$access_token=$apid.'|'.$appSecret;
while($userRow=$resultForUsers->fetch_assoc()){
try{
$response = $fb->sendRequest('GET', '/'.$userRow['user_facebook_id'], array(
'fields' => 'id,name,picture'
), $access_token);
}catch(Facebook\Exceptions\FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(Facebook\Exceptions\FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;}
}
请注意两件事:我的数据库中的所有用户都安装并批准了我的应用程序,我有真正的facebook ids
,第二件事:当我从数据库中硬编码ids
时,一个接一个,它不会返回任何错误。如果您遇到这样的错误,请帮助我。