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
Related
I am using Crashlytics in my application and I wanted to get user id and email along with each crash. I did something like this:
Crashlytics.setUserEmail(tokenModel.getEmail());
Crashlytics.setUserIdentifier(String.valueOf(tokenModel.getPk()));
I am doing this in my login screen, after the user has provided his email and successfully registered with the app, so as to get user id. The problem is, I am not getting these data in the crash reports.
What is the lifecycle and working of Crashlytics in above context? Do I need to set these fields every time the app opens?
I am not sure if it needs to be done every time you launch the app and the Crashlytics docs don't explicitly say it neither.
I know that we do it with every launch and it works - provided user info is displayed properly in the dashboard.
My suggestion would be to try send this information every time you initalize Crashlytics with Fabric.with(this, new Crashlytics());, as soon as you have your user data provided (for example after fetching his user profile from your server).
You need to select the issue, click in more details and at the top right corner you can see a label with Identifier.
You need to set it every time you initialise the Crashlytics. At least doing this it works.
if you are using this Crashlytics.setUserIdentifier(""); you can check in data tab in firebase. Fabric.with(this, new Crashlytics()); working fine.
If you look into codes of FirebaseCrashlytics than you can see that userId is being saved into the session. So I am sure that after restarting application your id will be restored.
Trying to integrate Facebook Android SDK 4.0 via a sample app.
Questions:
How can we check if the app has been de-authorized by the user in the app dashboard. Tried using the AccessTokenTracker in the new SDK documentation, but that doesn't seems to be getting called upon when i de-authorize the app.
The AccessTokenTracker is only called when i login or change the password on the account. Is there any other class for checking the de-authorization of an app?
The sample app: https://github.com/facebook/facebook-android-sdk/blob/b384c0655fe96db71229bfdcb981a522f3f1e675/samples/Scrumptious/src/com/facebook/scrumptious/MainActivity.java
Where exactly is the AccessToken stored in our app?
The documentation on the developer.facebook is real poor as of now.
I only want to use the SDK. I don't intend to use the Graph API along with that.
Any ideas is appreciated.
Thanks!
1) You won't get a call on the client when the user de-auths your app. What will happen is when you do a call, it will fail. The GraphResponse's getError will be not null. In this case, the FacebookRequestError's category is LOGIN_RECOVERABLE, as you need to take the user to the login flow again. You can call one of these methods to start that process with the response you received: https://github.com/facebook/facebook-android-sdk/blob/b384c0655fe96db71229bfdcb981a522f3f1e675/facebook/src/com/facebook/login/LoginManager.java#L96-L115
2) The access token is stored in your application's shared preferences under the key com.facebook.AccessTokenManager.CachedAccessToken
I'm using Twitter4J for posting some tweets.
When I try to post a tweet I open a webview with the authenticationURL to log in:
twitterRequestToken = twitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK);
Intent i = new Intent(FutbolTvActivity.this, TwitterWebLoginActivity.class);
i.putExtra("URL", twitterRequestToken.getAuthenticationURL());
startActivityForResult(i, 1);
If I complete the process I get logged OK and can send the tweet.
The problem is that if I click on cancel button on login web page and I try to login again I receive the next exception on
twitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK): No authentication challenges found
If I reuse the previous authentication URL the webview shows an error message saying this URL is too old.
Can anyone help me?
Finally, I found a solution:
At first time I was using:
twitter = TwitterFactory.getSingleton()
for getting the Twitter object. By this way the second time I call to getOAuthRequestToken() I get the error described above.
No, I'm using:
twitter = new TwitterFactory(configuration.build()).getInstance();
so I have different instances every time I start the related activity. By this way, I never call a second time over the same instance to getOAuthRequestToken() so I have no errors.
It might sound weird but try to set your time/date update automatically. Based on my previous experience this was the problem. When i set this and after the phone time is synced, everything works fine.
Changing Callback URL is not the reason, it take sometime to reset the keys. Check that your keys are correct and time is sync.. There is an issue arise few days ago which is fixed now. Make sure that any of the fields asking for URLs ("Website" and "Callback URL") are fully qualified, non-twitter.com domains.
May be it's possible your application name is already in use by another application. Experiment with different names and attempt to save again.
Check this link Temporary issue with creating applications
Check on your emulator, may be your device time is not sync. It won't work if your time is not sync.
The library is also updated.. Check this link Discussing API v1.1 and this too Issue with twitter: Unable to retrieve the access token. Status: 401.
Good luck with your project!
First of all I'm sure that my fb app id is valid because users can log in my Android app using facebook credentials until some days ago (I think it's before Feb break change).
Recently new users cannot log in my Android app using facebook any more because facebook keep saying that my fb app invalid (Error is: Invalid application fb-app-id) BUT old users who already authorized my Android app for accessing their info can still log in using facebook. (Old users can still login to my app using facebook credentials but new users cannot)
Does anyone know why this happen to my facebook app and how to fix it?
Edit: When access to https://graph.facebook.com/facebook-app-id I get this error
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
Thanks you.
If you're sure the app is not in sandbox mode (which was gema.megantara's answer), and hasn't been deleted for policy reasons by Facebook the only explanation I can think of is that you've restricted the app demographically (i.e by country or age)
If that's the case the API won't return the app's details unless you make the API call using a user access token for a user who meets whatever restrictions you've applied, and users who don't meet the requirements won't be able to use the app.
If that's what you've done, you can remove the restrictions via the API (via the restrictions field of the Application object or in the ''Advanced'' tab in the app settings in the App Dashboard
If using the frontend interface to change the settings, it's the ''App Restrictions'' field you want to edit, screenshot attached
Basically the same solution as the accepted answer, just updated for the latest FB developer site has been updated so you need do this:
Apps->Your App
Status+Review
Do you want to make this app and all its live features available to the general public? -> Yes
Usually if you get error like that when visit https://graph.facebook.com/523132271032907 is because the sandbox mode is on. Have you try to reset the secret key ?
I think, this is because FB does not check whether application id is valid when the user has already logged in. It likely assumes that if the check passed, the id is valid. Apparently, locking out the users after making the app id invalid has never been a design goal.
try replacing:
<string name="facebook_app_id">CHANGE-ME</string>
with:
<string name="facebook_application_id">CHANGE-ME</string>
I am using the official Facebook SDK for Android in my app.
I have managed to log in successfully,
but the problem arises when I try to log in as another user:
I click on the link that says Logged in as [name]... Not you?
but my application proceeds anyway and posts to my wall...
(as if I have clicked "Allow")
I discovered that clicking on that link throws a facebook exception and retries the request,
so I tried putting a call to logout() in the catch clause.
That made it possible to log in as a new user,
but the next time I run the app,
again, the old user is logged-in...
(Logged in as [old_user]. Not you?)
My question is:
Why does the first user's login persist forever
and how to properly handle a click on "Not You" link?
My current solution is to always call logout() before authorize() method
but this forces the user to always have to enter his/her email/password
which is not acceptable either.
The facebook access token is saved by SessionStore.
When loggin into Facebook, it will try to restore the access token from SessionStore.
So, I think you can explicitly call facebook.logout and SessionStore.clear() when user exit your application.