0

I'm trying to implement Phonegap Facebook Connect plugin via PhoneGap build and FB.getLoginStatus ALWAYS returns "unknown" even though I'm logged into Facebook and have granted access to my app. Here's my code:

JAVASCRIPT CODE:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady()
{

FB.init
({
    appId: 'XXXXX',
    status: true, // check login status
    cookie: true, // enable cookies to allow the server to access the session
    xfbml: false,  // parse XFBML
    oauth : true ,// enable OAuth 2.0           
    useCachedDialogs: false,
    nativeInterface : CDV.FB
});             

FB.getLoginStatus(function (response)
{
    alert('FB.getLoginStatus');

    if (response.status === 'connected')
    {
        alert('DUDE: connected to facebook');
    }
    else if (response.status === 'not_authorized')
    {
        alert('DUDE: not authorized for facebook');
    }
    else
    {
        alert('DUDE: not logged in to facebook: ' + response.status);
    }           
}, true);

        }

CONFIG.XML:

<gap:plugin name="com.phonegap.plugins.facebookconnect">
    <param name="APP_ID" value="XXXXXXX" />
    <param name="APP_NAME" value="APP NAME" />
</gap:plugin>

Any ideas on why facebook auth status is unknown? Thanks.

Tom Schreck
  • 5,177
  • 12
  • 68
  • 122

2 Answers2

0

You need to go through "Facebook Requirements and Set-Up" In Facebook Connect plugin

in Android:
If you plan on rolling this out on Android, please note that you will need to generate a hash of your Android key(s) and submit those to the Developers page on Facebook to get it working. Furthermore, if you are generating this hash on Windows (specifically 64 bit versions), please use version 0.9.8e or 0.9.8d of OpenSSL for Windows and not 0.9.8k. Big ups to fernandomatos for pointing this out!


step detail:
1. generate a hash key(s)    How to create Android Facebook Key Hash?
2. insert your hash key on facebook app setting panel( Settings ) (add Android platform and insert Key Hashes)
3. Go to Account > Edit Setting > Signing Key's tab in Adobe phonegap build then Click 'add a key...' upload your keystore file to make a Android buuiding key
4. select your android key to build app in phonegap build.

reference link:
login + logout + login = fail #1

Community
  • 1
  • 1
Shawn Wu
  • 487
  • 7
  • 18
0

This worked for me use the plug with the and the example

https://github.com/Wizcorp/phonegap-facebook-plugin/blob/a5c6be9/README.md

You can't relay on cookies and need to pass the access token by yourself.

Here is what you need to do:

1) Client side (note that I am using the older version of the plugin where the FB js was patched instead of new functions):

Pass the user id and accesstoken to the server:

FB.login(function(response) {
    if (response.authResponse) {
        // Use userID on authResponse because FB.getUserID() works in the browser but return null on device 
        var userId =  response.authResponse.userID;

        // Or use FB.getAccessToken()
        var accessToken = response.authResponse.accessToken;

        //use userId and accessToken to pass to the server (form or ajax call)
    }
}

2) Server Side (php)

//Get the accessToken from the request
$accessToken = $_REQUEST['accessToken'];
$facebook = new Facebook(array(
      'appId'  => '<YOUR APP ID>',
      'secret' => '<YOUR APP SECRET>'
    ));
$facebook->setAccessToken($accessToken);
//Now you have the right session setup and can call Graph API
$fbUser = $facebook->api('/me')
Stephen Ngethe
  • 1,034
  • 13
  • 24