com.google.gdata.client.GoogleService.setUserToken(android.accounts.AccountManager.getAuthToken(???))

I've got working code that uses the gdata to retrieve feeds from my user's Google Finance portfolios, but I had to use setUserCredentials(username,password). What I'd like to do is avoid asking the user for their username/password since the Android device already has access to their Google account.

I believe I should be able to do this with setUserToken(String), but I can't figure out how to get the appropriate token from Android. I've tried AccountManager.get(context).blockingGetAuthToken() but that's either not the correct call or I'm passing it the wrong arguments.

Has anyone gotten gdata working with the user's existing Google credentials on the phone?

Thanks in advance, Lenny


Asked by: Wilson390 | Posted: 25-01-2022






Answer 1

AccountManager.blockingGetAuthToken() is the correct call. Pass it an Account, and an String authTokenType -- In your case, "android" or "finance", your pick (the values of the strings it's looking for are not clearly documented).

The easy way to obtain an account is to do all your client comms as part of the onPerformSync() call on a class that implmenents a Sync Adapter. You can find a number of tutorials on getting a SyncAdapter set up. As part of getting your SyncAdapter going, you'll end up with a mess of permissions, probably like the following or so:

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> 
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> 
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> 
<uses-permission android:name="android.permission.READ_SYNC_STATS" /> 
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> 
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> 
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" /> 
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.finance" />

Those last two, again, sort of tricksy, dug them out of who knows where.

Answered by: Stuart638 | Posted: 26-02-2022



Similar questions

android - java.lang.NoClassDefFoundError: com.google.gdata.client.photos.PicasawebService

I´m using the Picasa Api and added the following libraries: activation.jar gdata-client-1.0.jar gdata-client-meta-1.0.jar gdata-core-1.0.jar gdata-media-1.0.jar gdata-photos-2.0.jar gdata-photos-meta-2.0.jar mail.jar Further I´m importing: import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import org.apache.http.H...


java - "The type com.google.gdata.client.GoogleService cannot be resolved" error message

I got this error message: "The type com.google.gdata.client.GoogleService cannot be resolved. It is indirectly referenced from required .class files" I'm using Google API because my goal is to use Google Apps but in Java, especially with Android. Here's the code : SpreadsheetService service = new SpreadsheetService(" Google Spreadsheet Demo"); // L...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top