I have an app where the Facebook Login was working great as of yesterday. I switched to AWS EC2 to get a bigger server for some capacity planning for today.
Unfortunately, the Facebook Login is no longer working. In particular, after getting the access_token from the JavaScript authorization, the getUser() call returns only 0. The code is below.
Since the server is the only thing that has changed (and IP) is there some configuration related to my server that I'm missing/unaware of?
if(isset($_GET["access_token"])) {
$access_token = $_GET["access_token"];
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
));
$facebook->setAccessToken($access_token);
$user = $facebook->getUser();
if($user) {
try {
$user_profile = $facebook->api('/me');
$user_name = $user_profile["name"];
$user_email = $user_profile["email"];
$fb_uid = $user_profile["id"];
$fb_access_token = $access_token;
} catch (FacebookApiException $e) {
$status_header = 'HTTP/1.1 500 Internal Server Error';
header($status_header);
header('Content-type: application/json');
echo json_encode(array('message' => 'Facebook Exception'));
exit;
}
} else {
$status_header = 'HTTP/1.1 500 Internal Server Error';
header($sta开发者_StackOverflowtus_header);
header('Content-type: application/json');
echo json_encode(array('message' => 'Facebook user does not exist', 'access_token' => $access_token, 'user' => $user, 'fb' => $facebook));
exit;
}
}
Two possible ideas:
The Curl library you are using on that system is not working properly. Try doing the call from the shell using some of the examples that are scattered around FB's site.
I once moved an app to a different server and had FB API calls inexplicably not work -- on the exact same code, after an rsync -- despite updating the new server IPs to be in our whitelist. I surmise that either the Facebook Developer App whitelist updating feature is broken or that IP was banned permanently from all of Facebook's APIs. If all else fails, try moving to a different EC2 instance in a different availability zone to see if it works there.
p.s. At the time, I emailed Facebook's "contact me if you have any problems" developer rep to check if the IP updating might be broken, but of course I got no response from the helpful team over there.
Verify the FACEBOOK_APP_ID and FACEBOOK_SECRET values are the correct ones and that the url you are accessing the site from is set as the site url and site domain on the application settings page.
Otherwise verify the PHP SDK versions are the same and the PHP versions are the same. This may help narrow down the problem.
精彩评论