I'm using Facebook SDK v4.6
I'm trying to setup a GraphAPI request class, it will communicate to Facebook Graph API if AccessToken is available. If not, it will pass an error to my Auth class which will initiate the login process
I'm using the code below to start the login process
LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("public_profile, user_photos, user_videos"));
However, the callback onCancel is always triggered whenever I do so, resulting to my application not being able to go through the Graph API process
I'm using a Facebook account which is an administrator for the Facebook app. Also the permissions user_photos and user_videos are already approved in Facebook side, so I don't think that's the problem.
Has anyone experienced the same problem?
I've been trying to look here for solution but majority of what I see is to call logout first before logging-in, but is that even correct?
I tried it on device without Facebook app installed, it repeatedly prompt the login dialog even though the user already logged-in previously (i concluded it's to be expected since we logged-out, but I wouldn't want user to repeatedly log-in after access token is expired) or is there no other way?
First make sure that,
App Id integrated with you app and App Id in Dashboard are the same or not.
Facebook user you are trying to login is a developer of your app.
(Because some permissions like 'publish_actions' will work with
developer account only not with the test user.)
Login function and Graph request should be called with main thread
of your app.
These are the issues i have faced. Still if you can't solve the issue , go through Facebook documentation once again.
Related
I am using parse.com's Android API and have added Facebook/Twitter login support. This is working fine.
The tricky part appears to be logging out.
If I log in to my app using Twitter:
ParseTwitterUtils.logIn(UserLoginActivity.this, twitterLoginCallback);
Or using Facebook:
ParseFacebookUtils.logInWithReadPermissionsInBackground(UserLoginActivity.this, null, facebookLoginCallback);
I am prompted in a web dialog to enter my twitter credentials and then allow or deny access to my app. Once I allow it, I am able to log in successfulyl and I have access to my screen name. All is well!
When I try to log out of my ParseUser, I do get logged out. However, if I click either the Facebook or Twitter login button again, I am pre-authenticated as my previous account, I can't switch accounts.
I have tried:
Checking Chrome and Browser and neither are logged in to Twitter.
Logging out of the native Twitter/Facebook app
My login logic started as simply:
ParseUser.logOut();
For Twitter I have tried
Uninstalling my application - This does fix it but is not an ideal solution.
Not calling Parse.enableLocalDatastore(this); in my Application as suggested here: https://stackoverflow.com/a/26338326/494356
Unlinking the Twitter account as suggested here: https://stackoverflow.com/a/34052718/494356. This also has the bad side effect of creating a new ParseUser each time (but still for the same Twitter account)
I have tried changing permissions from 'Read Only` to 'Read and Write' as suggested here https://stackoverflow.com/a/27714159/494356. (Why this would matter doesn't really make sense to me anyway)
I have tried setting the AuthToken to null
ParseTwitterUtils.getTwitter().setAuthToken(null);
ParseTwitterUtils.getTwitter().setAuthTokenSecret(null);
For Facebook I have tried
Uninstalling my application - This does not solve the problem.
Using the Facebook SDK Logout Features:
AccessToken.setCurrentAccessToken(null);
Profile.setCurrentProfile(null);
LoginManager.getInstance().logOut();
There used to be a Session.closeAndClearTokenInformation() as suggested here. But Facebook has Deprecated the Session class and it is no longer in the SDK.
Unlinking the Facebook account as suggested here. Again this causes duplicate ParseUsers and I am still able to log in using the saved credentials.
I would really appreciate any answers or suggestions. Even if you can only answer for either Twitter or Facebook but not both I would still love to hear it.
In our App the login/logout process works fine for Facebook, E-Mail and even an own build google login. I can tell you the differences I see on the first look and maybe one of it does the trick for you.
First of all we do not work with the ParseUser instance directly in our code, but have a MyUser class that extends ParseUser.
Second of all the login logic is encapsulated in a background service and not called directly in our Activity. That probably won't fix the problem. But in the background service we also cache the MyUser instance, retrieve it if we need it and use that instance to logout the user (MyUser.logOut()). And it is set to null after the logout.
Last but not least: are you running the latest versions of the Parse SDK?
Is it possible to login into facebook using my own login form in Android & get the facebook user id? I just want to validate the users without need them access their facebook.
In the Android facebook tutorial, the app have to open facebook first so that user can login but there is no automatic close after user login successfully.
Thanks in advance
No, you don't have a way to log the user in through facebook without using their official endpoints.
You can open some sort of browser with the authentication dialog (or the open graph one) but that still mean using their forms/ui (what ever you want to call it).
You should just use the android sdk without using the SSO, that way the sdk won't call the facebook application that is installed on the device (if at all) and will just call the auth dialog for you.
This is a better solution for you since it "abstracts" some things from you, takes care of the access token and more.
Here's a thread about disabling the SSO: How to disable Facebook single sign on for android - Facebook-android-sdk
I'm a bit confused about how facebook.logout(context) works.
Because even after calling log out, I am able to get access to information that requires an auth_token. So how is that even possible? I came across this topic, which let me a bit confused: https://stackoverflow.com/a/6597688/487940
After reading that answer, this is my question: So if the user grants access to [my] application, he will always be authenticated if he is logged into the [official] facebook application? Even if I try to call facebook.logout(context) in [my] application, he will be logged in and my application will be able to make calls to Facebook API?'
Sorry, about I'm not able to understand this behavior.
UPDATE: After reading Torid's reponse, I am confused about facebook.logout() function. What is the purpose of this function if it does not log the user out? Because, I don't see the purpose of calling this purpose anymore. It doesn't log the user out.
There are two independent things going on here: 1) whether your user has authenticated your app (with permissions) to Facebook and 2) whether your user is logged in to Facebook.
Authentication is required the first time your user uses your app and lasts until the user explicitly de-authenticates (e.g. through the Facebook web Account Settings -> Apps -> App Settings).
Log in may be required each time your user starts your app. But if you use the default SDK authorize(), that tries to do a Single Sign On (SSO), where if the Facebook app is logged in, your app is automatically logged in and uses the existing access token.
If you are using SSO, when you do a logout, that has no effect, as a real logout would have to log out the Facebook app - which the user might not like!
You can get around this behavior by doing an authorize of the form
authorize(this, PERMISSIONS, FORCE_DIALOG_AUTH, new LoginDialogListener());
which avoids SSO and forces a dialog login. Of course, that then forces your user to login each time you start your app - unless you save the login details / access token under the
covers (which is what the SDK does - check the source).
I'm using Facebook's Android API and everything works as expected with one exception. When I leave the Facebook app installed on the device (this is the stand-alone app, that has nothing to do with either the API or my app), and I call logout() on my Facebook object, it correctly voids the Facebook object but the next time I fire up the object it goes and retrieves the login data from the Facebook app and the login persists.
If I don't have the Facebook app installed on the device, everything works perfectly.
I'm curious if there's some mechanism I'm overlooking for forcing the Facebook app to not hold onto the login, or am I stuck having to tell my client (this is a custom app for a client, never going to market) that when they run this they will have to make sure to uninstall the Facebook app from the devices that they're running this on?
When you say the Facebook Android API, do you mean the Facebook Android SDK?
If so, when you call authorize, you have the option of specifying whether that is a single sign on (SSO) or a OAuth 2.0 dialog authorization. The default is SSO. If you authorize with SSO, and the Facebook app is present and logged in, then the authorize succeeds without going anywhere near the Facebook server.
If you do not use SSO, and use OAuth 2.0 dialog authorization, the user initially sees a login dialog plus an app authorization dialog, and after a successful login/authorization, the SDK keeps hold of an access token for subsequent authorizes.
Unfortunately, the SDK logout does not take account of SSO. It does a OAuth 2.0 expiresession and clears the access token, but it does not tell the Facebook app that the user has logged out. So that means when you do the next authorize (assuming it is an SSO) the Facebook app is still logged in, then the authorize succeeds without going anywhere near the Facebook server.
One way forward would be to not use SSO and require a OAuth 2.0 dialog authorization (using authorize(FORCE_DIALOG_AUTH)). That would require the user to login even if the Facebook app is present and logged in, but it would prevent the login persisting.
I want to use the facebook sdk and be able to automatically login after the app has already logged in once.
Currently from what I can gather if you use the facebook api and you have the facebook app installed and you have signed in with the facebook app then you don't have to login and you will be automatically logged in.
But if you don't have the facebook app then this automatic login will not happen. -----------I want to handle this case and be still able to automatically log in after the user has logged in with my app once.-------------. From my understanding the facebook sdk requires you to login if the facebook app is not there.
Also if the user has logged in once with my app, I will have the access token then as long as the access token has not expired then you don't need to log in again. But if the access token expires then you have to log in again.
Any help will be appreciated. Thanks.
The functionality you're describing is called single sign on. Facebook has an entire article dedicated to describing how it works and how to implement it. Enjoy:
http://developers.facebook.com/docs/guides/mobile/android_sso/