davidlks83 / google-spreadsheet-lib-android

Automatically exported from code.google.com/p/google-spreadsheet-lib-android
0 stars 0 forks source link

Using Android AccountManager for authentication #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is great. Could you please support AccountManager.getAuthToken() to 
authenticate against Google SpreadSheets? I'd rather not have to enter a 
password in an app.

Thanks,

Frederik

Original issue reported on code.google.com by m...@fredo.org on 28 Feb 2011 at 11:13

GoogleCodeExporter commented 9 years ago
Hi Frederik,

AccountManager.getAuthToekn() doesn't return correct authentication token (for 
SpreadSheet service). It seems there is problem in Google server (which is not 
a surprise).
But if you want to use AccountManager, you can take user_id and password from 
AccountManager and provide them into this Libraray.  

Hope it helps!
-Prasanta

Original comment by pprasant...@gmail.com on 28 Feb 2011 at 11:35

GoogleCodeExporter commented 9 years ago
Hi Prasanta,

you can't actually use AccountManager to get a username and password without 
having the same UID as the account's authenticator. I've modified 
SpreadSheetFactory.java to actually use AccountManager and it successfully 
generates tokens for the wise and the writely service. Instead of using 
username and password to call SpreadSheetFactory, you now have to hand it an 
Account and the current context. You can get a list of currently installed 
accounts with AccountManager.get(this).getAccountsByType("com.google");

Please have a look at the attached file and see if you could use it for future 
versions. I think it doesn't correctly deal with invalidating the tokens yet, 
but maybe you have an idea there.

Thanks,

Frederik

Original comment by m...@fredo.org on 12 Mar 2011 at 10:57

Attachments:

GoogleCodeExporter commented 9 years ago
I'm trying to use this patch. But I keep on getting the following error(s) 
exception: 

It's triggered at line 482 - "authToken = new 
LoginTask().execute(service).get();"
authToken remains null.

What might I be doing wrong?

W/System.err(28993): java.util.concurrent.ExecutionException: 
java.lang.ClassCastException: android.app.Application
W/System.err(28993):    at 
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:223)
W/System.err(28993):    at java.util.concurrent.FutureTask.get(FutureTask.java:82)
W/System.err(28993):    at android.os.AsyncTask.get(AsyncTask.java:340)
W/System.err(28993):    at 
com.pras.SpreadSheetFactory.login(SpreadSheetFactory.java:482)
W/System.err(28993):    at 
com.pras.SpreadSheetFactory.getAllSpreadSheets(SpreadSheetFactory.java:282)
W/System.err(28993):    at 
com.pras.SpreadSheetFactory.getAllSpreadSheets(SpreadSheetFactory.java:257)
W/System.err(28993):    at 
com.pras.SpreadSheetFactory.getAllSpreadSheets(SpreadSheetFactory.java:247)
W/System.err(28993):    at 
com.javier.AccTesterMain.onCreate(AccTesterMain.java:62)
W/System.err(28993):    at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err(28993):    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err(28993):    at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err(28993):    at 
android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err(28993):    at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err(28993):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(28993):    at android.os.Looper.loop(Looper.java:123)
W/System.err(28993):    at 
android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err(28993):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(28993):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(28993):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err(28993):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err(28993):    at dalvik.system.NativeStart.main(Native Method)
W/System.err(28993): Caused by: java.lang.ClassCastException: 
android.app.Application
W/System.err(28993):    at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:528
)
W/System.err(28993):    at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:1)
W/System.err(28993):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
W/System.err(28993):    at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(28993):    at 
java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(28993):    at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
W/System.err(28993):    at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
W/System.err(28993):    at java.lang.Thread.run(Thread.java:1096)
I/System.out(28993): [DEBUG] auth token for wise is null
I/System.out(28993): [HttpConHandler] 
URL=https://spreadsheets.google.com/feeds/spreadsheets/private/full
W/dalvikvm(28993): threadid=7: thread exiting with uncaught exception 
(group=0x400207e0)
E/AndroidRuntime(28993): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(28993): java.lang.RuntimeException: An error occured while 
executing doInBackground()
E/AndroidRuntime(28993):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
E/AndroidRuntime(28993):    at 
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(28993):    at 
java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(28993):    at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(28993):    at 
java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(28993):    at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
E/AndroidRuntime(28993):    at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
E/AndroidRuntime(28993):    at java.lang.Thread.run(Thread.java:1096)
E/AndroidRuntime(28993): Caused by: java.lang.ClassCastException: 
android.app.Application
E/AndroidRuntime(28993):    at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:528
)
E/AndroidRuntime(28993):    at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:1)
E/AndroidRuntime(28993):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
E/AndroidRuntime(28993):    at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/AndroidRuntime(28993):    ... 4 more

Original comment by jav...@ubillos.org on 9 May 2011 at 12:45

GoogleCodeExporter commented 9 years ago
I "fixed" the problem by adding a member "activity" where I pass the calling 
class.
It's a horribly ugly fix, but atleast that establishes that the error is when 
casting "this.context" to "Activity" in the call to accountManager.getAuthToken.

Original comment by jav...@ubillos.org on 9 May 2011 at 1:41