Android - Facebook API - How to authenticate two times? - android

I have a problem while trying to log in on Facebook for the second time. The first time the user enter its credentials, I start to upload some pictures in the background into its Facebook account.
However, in that period, another user can come and hit the Facebook button again. I expect that the previous request is still being processed, which is the case. However, I can't get the second user to log in WHILE THE FIRST PROCESSING (that is, the upload of the pictures of the first user) HAS NOT FINISHED YET.
What happens with the current version is that, when the second user hits my Facebook button, the Facebook API just assume that it refers to the previous user (because it is still running in the background). However, I want to start ANOTHER section with this new user, while the old one is still running in the background. How can I achieve that?
Here is my simple code (when the user hits my Facebook button on the screen, I call the following method):
private void uploadPictures(View target) {
mFacebook = new Facebook(getString(R.string.facebookappid));
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mFacebook.authorize(this, Settings.FACEBOOK_PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
PS: I have also tried to instantiate more than one Facebook and AsyncFacebookRunner objects, but it did not work (I get the same behaviour, that is, even though the objects are different, the login screen simply does not show up the second time (if the previous request is still being processed))!!!
Thank you so much in advance!

You're able to do something similar to this with the new 3.0 beta SDK. You can get it here and check out the SwitchUserSample.
You won't be able to use single sign-on (SSO) with the different users (they'll need to sign in via a webview dialog), but you'll get a different Session object that use can use for different users.

Related

Logout from Spotify with the sdk spotify-android-auth

I have an Android app, which the user can link to Spotify, with :
AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);
The problem is that I want the user to change his Spotify account so I want to logout the user from Spotify to log with another account. But the data of the connection are saved in the cache and when I use this line again :
"AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);", it does not show the connection dialog because the user is already connected.
In the doc, it says :
"To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed."
But the method clearCookies does not exist anymore. What can I do to logout the user and allow him to connect on another account ?
I've searched on the net and seems that this code
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, type, redirectUri)
.setShowDialog(true)
.setScopes(scopes).build();
took from this post it's your only choice to try to logout a user.
I can't test it, so you should try it yourself and see if works.
The documentation on the Spotify Android SDK is outdated and is not reflecting the new Spotify auth library on GitHub.
Spotify's Android SDK documentation is definitely outdated. My observation is that when you call
AuthorizationClient.clearCookies(context)
directly before starting Spotify's auth activity, it just works fine. But if you call it once and then expect that the user is logged out, when you start the activity later in the future, cached credentials keep messing around.
I do not prefer
builder.setScopes(arrayOf("")).setShowDialog(false).build()
as it shows you a "not you? Click to log out" option. So basically you need to log out on the Spotify UI, cannot do it from code.
In my case, the application saves the logged in user's email (I need that to show on the UI, anyway). When I want to log the user out programmatically, I just delete the saved email from the app and call
clearCookies()
when I start Spotify's Activity if the variable is empty.
A bit late, but you can use this AuthorizationClient.clearCookies(this) as
AuthenticationClient no longer exists

Facebook Login with Read and Publish(Write) permissions

I am trying Facebook Login in Android with LoginManager class. I want read and write permissions during login only. The issue I am facing is , If I try with
LoginManager.getInstance().loginWithReadPermissions();
LoginManager.getInstance().loginWithPublishPermissions();
If Facebook App is not installed, Facebook WebView loads up, I enter credentials, I see two permissions screen (One for Read and One for write) and then again Login Screen.Which basically, creates bad user experience.
It happens because, both loginWithxxxPermissions() methods,starts a new login flow.But actually, It should not show Login Screen for already logged in user.
I am not able to find any method to pass the accessToken to let me the method know that, the new permission query is for already logged in user.
Anyone, Please help me out or suggest some other alternative, But the requirement is clear. I need Read/Write permissions without showing Login screen twice.

Displaying google+ username after sign-in

I followed Google's tutorial on implementing the google+ api but it doesn't say anything about that dialog with the user's name that shows up at the top of your screen after signing in to your google+ account like many other games have. I can't find any information about different layouts either, like the loading screen that shows up sometimes after you've pressed sign-in.
You can use the API to request the users profile:
Person me = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (me != null) {
//me.getDisplayName();
}
It seems like what is displayed during the login process really depends on the speed of the device, the load on the device, and perhaps the network connection. In my case, most of the time the activity starts and disappears before I have a chance to read what it says (when user has already been authorized).
I think you can always count on your activity being paused then resumed if you call mGoogleApiClient.connect() when !mGoogleApiClient.isConnected(). I do not believe you can brand their Activity other than with your application logo.

android facebooksdk login and status update in one click

I need to implement a share via facebook button within an android app. I read the official facebook sdk doc and the only way I can find to do this, is to first let user authenticate with a login button, and then let him update the status.
Since the facebook stuff is really marginal in the application, I'd like to find a way to let the user click only one time on a button (a custom one, not a com.facebook.widget.LoginButton), and then if already logged in, update the timeline, else, login and directly update timeline.
I really need to let the user accomplish the task in these steps:
-click on my button
-if not logged in, do login in dialog, new activity or whatever
-open a dialog (custom or from facebook sdk,doesn't matter) with an edittext for message and update/cancel buttons
I read this tutorial, but everything used there seems to be deprecated (even when trying to initialize com.facebook.android.Facebook objects got a deprecated warning), so I wonder if there is a good way to implements a one click status update.
I already did it this way for twitter, there must be some way to do it for facebook too!

Running Facebook Login / Publish as Seperate Class

I have followed : https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/
I have created a separate page as in the example and works perfectly fine.
My issue is now I want to add the Login button to my home page and the publish button on a different page. Is it possible to convert this into a separate class that I can call from anywhere?
Has anyone done this and can point my in the right direction.
Sorry if this has been asked before. I am very new to Facebook SDK
Thanks for your time
Yes, if you use the Active Session, you should be able to call Session.getActiveSession() from any activity, and it should return you the right thing. So the page with the login button would create the active session, and the page with the publish button would get the active session, and call requestNewPublishPermission and do the publish.
There are 2 outstanding issues:
You need to ensure that the page with the login button appears in your app before the page with the publish button (at least the first time, when the user initially logs in).
In subsequent restarts of your app (after the user has already logged in), you can use the UiLifecycleHelper to manage, restore, and auto-open the active session for you.

Categories

Resources