是Facebook的用戶是測試您可以更改名稱和密碼,否則返回錯誤代碼(#200)您沒有足夠的權限來執行此操作
**我的解決方案:**
public function isTestUser($facebook_uid){
FacebookSession::setDefaultApplication(config_item('APP_ID'), config_item('APP_SECRET'));
$session = FacebookSession::newAppSession();
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
return FALSE;
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
return FALSE;
}
$request = new FacebookRequest(
$session,
'POST',
'/'.facebook_uid,
array(
'password' => 'password',
'name' => 'Test Username'
)
);
try {
$response = $request->execute();
} catch (FacebookRequestException $ex) {
// (#200) You do not have sufficient permissions to perform this action
// (#100) Invalid password
// (#100) Invalid name
return ($ex->getCode() == 100) ? TRUE : FALSE;
} catch (\Exception $ex) {
return FALSE;
}
/*
object(Facebook\GraphObject)#1714 (1) {
["backingData":protected]=>
array(1) {
["success"]=>
bool(true)
}
}
*/
$graphObject = $response->getGraphObject();
return ($graphObject) ? TRUE : FALSE;
}
你實際上可以檢查用戶是否是粉絲:http://developers.facebook.com/docs/reference/rest/pages.isFan/。這是比取他的喜歡更可靠的方法(我已經測試了一段時間,FB有時會返回用戶的空白頁面列表)。你測試用戶是否是測試用戶的想法很好。 –