digicom Posted March 29, 2014 Share Posted March 29, 2014 I have a facebook app working at https://apps.facebook.com/inboxcupid/ When trying to log in from a mobile device, the GetUser method always return 0. It actually creates a redirect loop as the page is constantly redirected to login, return to the app page and then back to login. It's imperative to know that this code works just fine on a desktop but fails on mobile. Here is my code: require_once ('facebook.php'); $config = array( 'appId' => '*****', 'secret' => '*****' ); // Create the Facebook object $facebook = new Facebook($config); $login_params = array( 'canvas' => 1, 'scope' => 'basic_info, user_about_me, user_birthday, user_relationships, user_relationship_details, user_location, user_photos', 'fbconnect' => 1, ); $user = $facebook->getUser(); if($user) { try { $permissions = $facebook->api("/me/permissions"); if( !array_key_exists('basic_info', $permissions['data'][0]) || !array_key_exists('user_location', $permissions['data'][0]) || !array_key_exists('user_about_me', $permissions['data'][0]) || !array_key_exists('user_birthday', $permissions['data'][0]) || !array_key_exists('user_relationships', $permissions['data'][0]) || !array_key_exists('user_relationship_details', $permissions['data'][0]) || !array_key_exists('user_photos', $permissions['data'][0]) ) { $login_url = $facebook->getLoginUrl($login_params); echo "<script" . " type='text/javascript'" . ">top.location.href = '$login_url';</script>"; } } catch(FacebookApiException $e) { $login_url = $facebook->getLoginUrl($login_params); echo "<script" . " type='text/javascript'" . ">top.location.href = '$login_url';</script>"; error_log($e->getType()); error_log($e->getMessage()); } } else { $login_url = $facebook->getLoginUrl($login_params); echo "<script" . " type='text/javascript'" . ">top.location.href = '$login_url';</script>"; } If anyone can help me figure it out I'll be thankful. Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 30, 2014 Share Posted March 30, 2014 Hi Guessing: I don't know much about FB API, think the logic is the problem here though. GetUser method always return 0 If it is returning a false then it seems to be is missing what you need to run through your methods correctly, returning a false, might want to do something like: If ($user == false){ //redirect to login } Suggest: comment out the redirection line and echo out the variables to see if they return correctly. Don't know if any of this will help, but worth a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.