How to use facebook connection in mobile web application using OAuth dialog

Now I am developing a mobile web application using a connection to facebook, but I am having problems with the OAuth dialog. For my reference, I use the following documents on facebook:

http://developers.facebook.com/docs/guides/mobile/#web

I choose to use OAuth Dialog instead of the login button because mobile browsers do not recognize FBML (I use the Blackberry browser when testing). The OAuth dialog box also allows me to add a list of permissions within the scope settings. But the problem is that when I logged in using the OAuth Dialog, the $ me parameter was not recognized so that the login button was still displayed and did not change to the logout button. Here is an example of my code:

$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
    $accessToken = $facebook->getAccessToken();
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}
if ($me) {
  echo "<img src=\"images/logoutFB.gif\">";
} else {
  echo "<a href=\"http://www.facebook.com/dialog/oauth?scope=user_about_me,user_activities,user_birthday,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes&client_id=".$facebook->getAppId()."&redirect_uri=".urlencode("http://MYURL.COM")."&display=wap\"><img src=\"images/loginFB.gif\"></a>";
}

Can I use the $ me parameter if I use the OAuth dialog to connect to facebook? So, how do I know if I am already registered with facebook or not if I use OAuth Dialog? Please help if you have a solution.

+5
1

, PHP-SDK

getSession() getUser():

require './src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '135669679827333',
  'secret' => 'xxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {

    $user = null;
  }
}
+2

All Articles