Jump to content

Recommended Posts

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.

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. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.