I have a screen that popups up that Facebook login thing with the following code:
//facebook stuff
if (Session.getActiveSession() == null || Session.getActiveSession().isClosed()) {
Session.openActiveSession(this, true, null);
}
If the user hits the "back" button and dismisses the login thing, it automatically sends them to the screen that was supposed to be facebook protected (and has errors because no user is logged in).
How should I handle this? I see that in the old sdk or whatever, it had:
facebook.isSessionValid()
Is there still a way to do this? If so, HOW would I actually do it? Some sort of while loop until they finally stop trying to back out? Is there a way to disable backing out of that screen? I don't generate that screen at all: facebook does. Is this just a bug I have to live with?
Edit:
Corollary to this is that I have just noticed that if I use the facebook app to logout, the facebook sdk doesn't tell me this in my own app: It still authenticates. Even worse is when it does it even after I have logged out, then logged in as an entirely different user using the facebook app. How do I handle this?
Edit: More Code
This is now how I log in to facebook (in the Activity's onCreate) and ask to get my graph user and my friends' (gets me first, then once that asynch thing is done, gets friends)
if (Session.getActiveSession() == null || Session.getActiveSession().isClosed()) {
Log.v(CLASS_NAME, "Logging into facebook");
//Session.openActiveSession(this, true, new Session.statusCallback());
final Session.StatusCallback sessionStatusCallback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if(exception != null)
{
// Handle fail case here.
Log.v(CLASS_NAME, "Facebook login error " + exception);
return;
}
// If session is just opened...
if(state == SessionState.OPENED)
{
// Handle success case here.
Log.v(CLASS_NAME, "Facebook login success!");
return;
}
}
};
Session.openActiveSession(this, true, sessionStatusCallback);
}
//annonymous inner class
final Callback<ArrayList<GraphUser>> inner_callback_class2 = new FacebookHelper.Callback<ArrayList<GraphUser>>() {
#Override
public void setResult(ArrayList<GraphUser> result) throws Exception {
// TODO Auto-generated method stub
for(GraphUser user : result){
friends.put(user.getId(), user);
}
friends.put(me.getId(), me); //i can see my own comments as well
//get comments
//ArrayList<String>tmp = new ArrayList<String>();
//tmp.add("Jenny");
//tmp.add("Charles");
//initial comment call so I can view them
//
getComments();
}
};
//annonymous inner class
FacebookHelper.Callback<GraphUser> inner_callback_class = new FacebookHelper.Callback<GraphUser>() {
#Override
public void setResult(GraphUser result) throws Exception {
// TODO Auto-generated method stub
me = result;
Log.v("ANYTHING", me.getName());
//make sure i have an id before I do anything
FacebookHelper.getMyFriends(Session.getActiveSession(),inner_callback_class2);
//post comment
//RailsServerHelper.postComment("Comment Testing", movie.id, myID, currentNPT);
}
};
FacebookHelper.getMyID(Session.getActiveSession(), inner_callback_class);
This is how I get my friends (in a static helper class):
public static void getMyFriends(final Session session, final Callback<ArrayList<GraphUser>> callback){
Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
// TODO Auto-generated method stub
ArrayList<GraphUser> tmp = new ArrayList<GraphUser>(users);
try {
callback.setResult(tmp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
request.executeAsync();
}
The only other facebook thing I have is that whole clear the session thing you suggested:
#Override
public void onDestroy(){
Session.getActiveSession().closeAndClearTokenInformation();
Log.v(CLASS_NAME, "Clearing facebook session");
pleaseStop = true;
super.onDestroy();
}
It won't let me log back in at all. I have two devices I'm testing it on.
The first device was working fine originally with one profile, but when I tried to try a second profile it wouldn't log the first one out, so I did that closeAndClearTokenInformation() thing. That resulted in NO profile, and it won't pop up the whole facebook log in stuff anymore. I think there is no profile because it always prints out "Logging into facebook", and the getMe call thing never works. (Just from describing my code here I see I can put the getMe stuff in the facebook log in callback, though) It also never prints the success statement I put in the callBack, and on the first device it prints out the error statement if I hit the back button (no matter how long I sit at that screen).
The second device never managed to get a profile logged in because the back button was hit on the login screen. Ever since that, the system seems to think its "logged in" as nobody, and nothing I do can get it to refresh. I don't ever see it attempting to log in like the first device. The closeAndClear call thing seems to do nothing on this device. If relevant, the second device is a virtual simulator running on an entirely different machine.
On the actual device, what I see is:
01-24 07:16:04.669: V/MakeAndViewCommentsActivity(3677): Logging into facebook
And then a bunch of system messages (I waited over ten minutes), none of which seem to have warnings or errors, and then:
01-24 07:29:05.548: V/MakeAndViewCommentsActivity(3677): Clearing facebook session
01-24 07:29:05.552: V/MakeAndViewCommentsActivity(3677): Facebook login error com.facebook.FacebookException: Log in attempt aborted.
Why isn't the facebook openActiveSession ever returning?
Edit: The facebook sample apps still have the original log in working, but don't care if I log out or change users in the actual facebook app. I guess they don't include any session clearing either?
Edit: When I have a print statement of:
Log.v(CLASS_NAME, "Facebook callback with state: " + state);
I see:
01-24 09:10:54.333: V/MakeAndViewCommentsActivity(4869): Facebook callback with state: OPENING
does the callback only get called once? Or is it going to be theoretically called again with a state of "OPEN" if it completes?
SOLUTION:
Edit: Looking up the fact that it never leaves the "OPENING" state helped me a lot, it turns out I had to add the code:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession()
.onActivityResult(this, requestCode, resultCode, data);
}
And then it just worked! I have no idea why. I guess I will do research on this, but I"m glad I can finally change users.
You're passing in a null callback. If you implemented the callback, you would see that the callback would be called, and if you checked state.isClosed(), it would return true (and the state should be CLOSED_LOGIN_FAILED). There should also be an exception in the exception parameter. You cannot disable the ability for users to back out of SSO, that's by design.
You're also correct in that there are no notifications if the user logs out of the facebook app. One way to have a better user experience is to always display the user's name and profile picture when you're doing something on behalf of the user (like posting a status), so it's immediately obvious that it's not the correct user. The other options is to always call session.closeAndClearTokenInformation every time your app exits. This way, you're always starting a fresh session, and if the user has the facebook app installed, it's still a very fast auth (no additional buttons to press). The drawback is that if they don't have the facebook app, then it will pop up a web dialog for login every time (but you can probably work around that by checking for the existence of the FB app).
Related
When attempting to login and signup through Facebook, the method isNew() somehow always returns false, even if the "_User" table is empty or if the user is logging in for the first time (signing up).
According to the docs:
isNew(): Indicates whether this ParseUser was created during this session through a call to ParseUser.signUp() or by logging in with a linked service such as Facebook.
Here's the code:
private void loginWithFacebook() {
ParseFacebookUtils.logInWithReadPermissionsInBackground((Activity) getContext(), null, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
if (user.isNew()) {
onLoginListener.onSignupWithFacebook();
} else {
onLoginListener.onLoginWithFacebook();
}
} else if (e != null) {
handleException(e);
}
}
});
}
Other people have come across similar problems and fixed it, but the solutions they've come up with don't apply to my case:
Facebook login with Parse always returns false in user.isNew() Android
Facebook Login not working properly (Parse)
User.isNew() returns false when it should return true
Apart from that, everything else seems to be working fine. The user data is created and stored on the table just like it normally should. Any suggestions?
remove enableAutomaticUser() if you have written in Application or BaseActivity class
docs says that this method will Enables automatic creation of anonymous users.
remove except this three and try may help you.!!
FacebookSdk.sdkInitialize(getApplicationContext());
Parse.initialize(this,getString(R.string.parse_app_id),getString(R.string.parse_client_key));
ParseFacebookUtils.initialize(this);
I have the following code. It is a simple test of the callback function of the LoginButton in Facebook's Android API.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setReadPermissions("email");
loginButton.setReadPermissions("public_profile");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.e("SUCCESS", "LOGIN SUCCESSFUL");
}
#Override
public void onCancel() {
Log.e("CANCEL", "Cancelled");
}
#Override
public void onError(FacebookException e) {
Log.e("ERROR", "Facebook Exception");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
The only problem is that whenever I click the loginButton, a dialog appears and disappears for a brief moment, and then the logcat prints out the "CANCEL" text. I cannot seem to fix this error, and I'm not clicking cancel, because that dialog simply shows up and immediately disappears.
Please help me fix this?
As Facebook now requires review of applications which use publish access, you need to log into Facebook Developers Console, in Apps section select your app, click on Roles and add tester (or admin) role.
After this you should be able to get proper access token.
This answer helped me in similar situation.
https://stackoverflow.com/a/31625256/1987045
Call LoginManager.getInstance().logOut(); before attempting a sign in.
I encountered this issue.
It seems to be the case that if you attempt to login (using logInWithReadPermissions or logInWithPublishPermissions) when you already have an access token (with all of the required permissions) then the onCancel callback is executed.
That is to say you should not be logging the user in because the user is already logged in. Check for this first.
My solution:
I had the same problem. The callback was always received by onCancel() method.
I was performing a native login (meaning I was using Facebook App), so after talking with a work-mate, I unistalled my Facebook App to check whether a non-native loging was possible and run my app. To my surprise, before receiving the callback on the onCancel() method, a message informed me my Facebook App ID was wrong, so that was all. I had copied a wrong one instead of the one you get from https://developers.facebook.com/apps.
Now it works and even displays the permissions dialog. What I mean with this is that always try native and non-native. Maybe you get the answer from any of them.
For me this happened because I was calling finish() on my Activity before the Facebook callbacks could complete, causing the activity to finish with RESULT_CANCELED instead of RESULT_OK.
More specifically, my buggy code looked something like this:
#Override
protected void onStart() {
super.onStart();
if (!mAuthRequested) {
mAuthRequested = true;
promptSignIn();
} else {
finish();
}
}
What was happening is that once Facebook's auth activity finishes, onStart() gets called again, but else { finish(); } is invoked before any of Facebook's callbacks are. The fix was to remove the else block.
I hope this helps someone!
I am relatively new to android and facebook so please bear with me. IMPORTANT NOTE: Wherever I type h.. that means http://www. I'm not intending to post links here but I have to in order to explain this (my permission only allows 2 links) so please bear with me.
This app does a facebook post using the FacebookDialog.ShareDialogBuilder. This all works great now IF the image for the post using the .setPicture method is given a static hardcoded URL h..example.com/share_name/image_name.png. In that case the post works and the picture shows up on the post and everything is fine.
However, the image sent to the post is dynamically created by the app. Therefore I am sending the image to facebook's staging area which also works fine.
The Request.newUploadStagingResourceWithImageRequest returns a response that has the JSON encoded URI of the location of
the image in facebook's staging area.
The problem is that the FacebookDialog.ShareDialogBuilder doesn't like that URI location. Somehow it's not formed properly or something or I'm just doing something wrong.
Here are the details and what I've tried:
1) uriMine, the location where the image gets stored, as it is originally returned from facebook's staging resource upload call is:
"fbstaging://graph.facebook.com/staging_resources/MDE4NTY0NzE4MDQ0MTUwNjA6MTM5ODI2Nzc3Ng==". I don't know what the protocol "fbstaging:" is all about (I searched and searched online but nothing) but I
ran the app as is with that at first. The result was, well, unpredictable results apparently, as it got stuck in a loop (the looper class kept repeating in no particular pattern). It would show the post screen but you couldn't type in a message as it would lock up, close, repeat etc...
2) After getting a little education online about well formed URL's I replaced the fbstaging:// with h.. and thus changed the uriMine variable to the following:
h..graph.facebook.com/staging_resources/MDE4NTY0NzE4MDQ0MTUwNjA6MTM5ODI2Nzc3Ng==
This solved the endless loop problem (made the post work fine) except it would not show any image.
3) To see if it would work with any old normal URL of the form h..blablabla.com/image_resource I hardcoded URL's of a few images online and it worked fine, and showed the images.
4) Ok, I promise, I'm all most done (whew!). So, where it stands right now is:
a) passing uriMine as fbstaging://graph.facebook.com/staging_resources/etc etc
makes it freak out.
b) sending a normal URL of an online resource works fine (formed as a browser forms it, by the way).
c) prepending http://www. instead of the fbstaging:// makes the post work but facebook doesn't show the image, as if it can't find it.
By the way, going directly to the above by copy/pasting it into a browser gets redirected to the following:
h..dnsrsearch.com/index.php?origURL=http%3A//www.graph.facebook.com/staging_resources/MDE4NTY0NzE4MDQ0MTUwNjA6MTM5ODI2Nzc3Ng%3D%3D&r=
as apparently it can't find it.
SO:
What is it about that URI that is wrong or what am I missing? Please help.
Thank you very much for your time and patience reading this.
public class FacebookActivity extends Activity {
// initialize the global object to enable passing of activity to facebook dialog
public GlobalClass globalObject = new GlobalClass();
private UiLifecycleHelper uiHelper; // for Facebook...to mimic android's activity life cycle
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);
// set the calling activity...to pass to Face book
globalObject.setCurrentActivity(this);
// start Facebook Login
Session currentSession = new Session(this);
currentSession = Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(final Session session, SessionState state, Exception exception) {
// this callback should fire multiple times, be sure to get the right one i.e. session.isOpened()
if (session.isOpened()) {
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Bitmap bitmap = takeScreenshot();
Request imageRequest = Request.newUploadStagingResourceWithImageRequest(Session.getActiveSession(), bitmap, new Request.Callback() {
#Override
public void onCompleted(Response response) {
String uriMine = "";
JSONObject data = response.getGraphObject().getInnerJSONObject();
try {
uriMine = data.getString("uri");
uriMine = "http://www." + uriMine.substring(12); // strip off the "fbstaging://" from the uri
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG))
{
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(globalObject.getCurrentActivity())
.setLink("https://play.google.com/store")
.setPicture(uriMine)
.setRequestCode(NativeProtocol.DIALOG_REQUEST_CODE)
.setApplicationName("This is the App Name")
.setName("This is the name")
.setDescription("This is the description")
.setCaption("This is the caption")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
else
{
Toast.makeText(globalObject.getCurrentActivity(), "Please install the Facebook App first from Google Play.", Toast.LENGTH_LONG).show();
}
}
});
imageRequest.executeAsync();
}
}
}).executeAsync();
}
}
});
}
The staging resource endpoint is only used for staging binary data for open graph objects or actions, and is not meant for the regular link shares. See the documentation here: https://developers.facebook.com/docs/reference/android/current/class/Request/#newUploadStagingResourceWithImageRequest
In this case, you can either use the PhotoShareDialogBuilder (but then you can't add a link), or you can upload the image to your own hosting service, and use an http/https url in the setPicture method.
I'm have a feature on my Android app where the user authorizes the app and shares a link.
I also need to give an option for the user to logout of facebook and I need to conditionally disable this button if the user is not logged int (or not authorized the app).
I can't seem to find the API call on the Android SDK that would let me ask FB if the user is logged in or not.
What I have found is getAccessExpires():
Retrieve the current session's expiration time (in milliseconds since
Unix epoch), or 0 if the session doesn't expire or doesn't exist.
Will checking if the session equals 0 be the way to go? Or is there something I'm missing?
Facebook SDK 4.x versions have a different method now:
boolean loggedIn = AccessToken.getCurrentAccessToken() != null;
or
by using functions
boolean loggedIn;
//...
loggedIn = isFacebookLoggedIn();
//...
public boolean isFacebookLoggedIn(){
return AccessToken.getCurrentAccessToken() != null;
}
Check this link for better reference https://developers.facebook.com/docs/facebook-login/android
check this heading too "Access Tokens and Profiles" it says "You can see if a person is already logged in by checking AccessToken.getCurrentAccessToken() and Profile.getCurrentProfile()
I struggled to find a simple answer to this in the FB docs. Using the Facebook SDK version 3.0 I think there are two ways to check if a user is logged in.
1) Use Session.isOpened()
To use this method you need to retrieve the active session with getActiveSession() and then (here's the confusing part) decipher if the session is in a state where the user is logged in or not. I think the only thing that matters for a logged in user is if the session isOpened(). So if the session is not null and it is open then the user is logged in. In all other cases the user is logged out (keep in mind Session can have states other than opened and closed).
public boolean isLoggedIn() {
Session session = Session.getActiveSession();
return (session != null && session.isOpened());
}
There's another way to write this function, detailed in this answer, but I'm not sure which approach is more clear or "best practice".
2) Constantly monitor status changes with Session.StatusCallback and UiLifecycleHelper
If you follow this tutorial you'll setup the UiLifecycleHelper and register a Session.StatusCallback object with it upon instantiation. There's a callback method, call(), which you override in Session.StatusCallback which will supposedly be called anytime the user logs in/out. Within that method maybe you can keep track of whether the user is logged in or not. Maybe something like this:
private boolean isLoggedIn = false; // by default assume not logged in
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
if (state.isOpened()) { //note: I think session.isOpened() is the same
isLoggedIn = true;
} else if (state.isClosed()) {
isLoggedIn = false;
}
}
};
public boolean isLoggedIn() {
return isLoggedIn;
}
I think method 1 is simpler and probably the better choice.
As a side note can anyone shed light on why the tutorial likes to call state.isOpened() instead of session.isOpened() since both seem to be interchangeable (session.isOpened() seems to just call through to the state version anyway).
Note to readers: This is now deprecated in the new FB 3.0 SDK.
facebook.isSessionValid() returns true if user is logged in, false if not.
Session.getActiveSession().isOpened()
returns true if user is logged in, false if not
Android Studio with :
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
then check login like as:
private void facebookPost() {
//check login
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken == null) {
Log.d(TAG, ">>>" + "Signed Out");
} else {
Log.d(TAG, ">>>" + "Signed In");
}
}
#diljeet was right. https://stackoverflow.com/a/29375963/859330
In addition, use
return AccessToken.getAccessToken() != null && Profile.getCurrentProfile()!=null;
It always works this way.
For Facebook Android SDK 4.x you have to use the "AccessToken.getCurrentAccessToken()" as said by #Diljeet but his check didn't work for me, I finally checked it by doing:
Activity "onCreate":
facebookAccessToken = AccessToken.getCurrentAccessToken();
To check if the session is still active (I made it in the "onResume" method but do it where you need):
if(facebookAccessToken != null){
sessionExpired = facebookAccessToken.isExpired();
}else{
sessionExpired = true;
}
More info in https://developers.facebook.com/docs/facebook-login/android
This seems to be working quite well with the new sdk.
private boolean isFacebookLoggedIn(){
Session session = Session.getActiveSession();
if (session != null) {
//Session can be open, check for valid token
if (!session.isClosed()) {
if(!session.getAccessToken().equalsIgnoreCase("")){
return true;
}
}
}
return false;
}
I had the same issue. Here is my solution using SDK 4.0:
First of all, in your activity dealing with login check, be sure to call this primary:
FacebookSdk.sdkInitialize(this.getApplicationContext());
In your onCreate method put this :
updateWithToken(AccessToken.getCurrentAccessToken());
new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
updateWithToken(newAccessToken, handler);
}
};
Then add the method called:
private void updateWithToken(AccessToken currentAccessToken) {
if (currentAccessToken != null) {
fillUIWithFacebookInfos(handler);
} else {
login();
}
}
This way will handle the already logged in user and the newly logged in user.
I was using FB sdk for just for login..
Facebook developers reject my app, Because whenever user login, I send logout.. I dont matter user profile data... I just use FB for login.. FB tells if user login... dont send lgout...
I find Hacking way...
Now my app doesnot send logout whenever user login.... Whatever user login with,Google,Facebook,or normal.. When they click logout... In this three condition
I use
LoginManager.getInstance().logOut();
No matter which platform they use... There is no crash :)
I am trying to use the Android Facebook SDK - but with no luck.
The problem is that the Facebook Login window starts loading, but before anything happens it disappears. This is the behaviour on an actual device, on the emulator all is good.
What I have done:
downloaded the SDk from here
added the java files to my project.
created a facebook application.
Got the Key Hash value and updated my facebook app.
But I cant get the Login window to appear. I dont see any error on the logcat, only this:
ActivityManager( 2698): Starting: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras)
ActivityManager( 2698): Trying to launch com.facebook.katana/.ProxyAuth
ActivityManager( 2698): Displayed com.facebook.katana/.ProxyAuth: +371ms (total +466ms)
Any ideas?
10X :)
EDIT:
It seems adding these lines of code to the activity solved the problem:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
Got if from here: SO Question
That logcat error from com.facebook.katana is from the Android Facebook app. Is that installed on the phone? It sounds like it is and you are defaulting to Single Sign On (SSO)?
Try doing your authorize as
authorize(this, PERMISSIONS, FORCE_DIALOG_AUTH, new LoginDialogListener());
which avoids SSO and forces a dialog login.
If that circumvents your crash, then the most likely cause is a mismatch between the SDK and the installed Facebook app. They do tend to be quite picky about working together. If so, you'll probably have to try several different versions of each before you find a stable pair.
Do you already install on device native application facebook? Because com.facebook.katana - this is from facebook application. It could happen, because already auth by this application.
What I do?
I comments in facebook.java code:
public void authorize(Activity activity, String[] permissions, int activityCode, final DialogListener listener) {
boolean singleSignOnStarted = false;
mAuthDialogListener = listener;
// Prefer single sign-on, where available.
// if (activityCode >= 0) {
// singleSignOnStarted = startSingleSignOn(activity, mAppId, permissions, activityCode);
// }
// Otherwise fall back to traditional dialog.
if (!singleSignOnStarted) {
startDialogAuth(activity, permissions);
}
}
Also I try do multi login and find problem, when I auth with one login/password, try add new login, show facebook dialog and in browser auto page login show and immediately disappears. Because occurred login with previos data. When I in facebook.java:
disable in startDialogAuth cookies.
private void startDialogAuth(Activity activity, String[] permissions) {
Bundle params = new Bundle();
if (permissions.length > 0) {
params.putString("scope", TextUtils.join(",", permissions));
}
// CookieSyncManager.createInstance(activity);
Util.clearCookies(activity);
dialog(activity, LOGIN, params, new DialogListener() {
public void onComplete(Bundle values) {
// ensure any cookies set by the dialog are saved
// CookieSyncManager.getInstance().sync();
setAccessToken(values.getString(TOKEN));
setAccessExpiresIn(values.getString(EXPIRES));
if (isSessionValid()) {
Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login Success! access_token=%s expires=%s", getAccessToken(), getAccessExpires());
mAuthDialogListener.onComplete(values);
}
else
mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
}
public void onError(DialogError error) {
Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login failed: %s", error);
mAuthDialogListener.onError(error);
}
public void onFacebookError(FacebookError error) {
Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login failed: %s", error);
mAuthDialogListener.onFacebookError(error);
}
public void onCancel() {
Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login canceled");
mAuthDialogListener.onCancel();
}
});
}
You might want put some debug messages (log.v()) in each of the Facebook Dialog events (onComplete, onFacebookError, onError, onCancel). I had the same problem; though, my problem was related to the key hash, I had the incorrect keyhash. If the keytool doesn't ask you for a password, it gives you the incorrect key. With the incorrect keyhash, I got the same behavior as you.
Another thing might be that you are already logged onto Facebook in your device. Therefore, it doesn't need to ask for your permission. If that's the case, log out of Facebook, then run your application.