I am trying to get to the app login screen on Facebook. When the activity is started, the screen shows a facebook loading page then disappears and the page is set to the R.layout.main.
I must be missing the point here, but how do I get to the app login page for the user to login please.
I have been following the tutorial based at https://developers.facebook.com/docs/mobile/android/build/#enablesso
FYI – I have removed the APP_ID
package com.example.facebook;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("APP_ID");
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
* Get existing access_token if any
*/
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
Thank you for your assistance.
Seems your Mobile contains Facebook Native App so , it might throws login failed invalid key error in Logcat.
If it happens that is problem due to Single Sign On .. So you need to create Android Key Hash and register in your app..
Follow this Steps to do so.
You can disable Single Sign On in Single line and no need to use Create Hash Key but this is not recommended way to handle.
Add -1 or Facebook.FORCE_DIALOG_AUTH in to authorize()