Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Authenticating to Google Docs

Authenticating to Google Docs

Put your problem here if it does not fit any of the other categories.

Authenticating to Google Docs

Postby emooney » Fri Mar 26, 2010 4:37 am

My goal is to have the ability to create/append a google spreadsheet when the user chooses to upload their data from my app. I don't want to ask the user to enter their username and password every time. Plus, they're already authenticated to their google account because they're on their google phone.

In reading the GSpreadsheet docs, once their username and password is sent to google for verification, they send back an authToken and we communicate by passing the authToken from there. But I already have access to an authToken in android:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         AccountManager mgr = AccountManager.get(this);
  3.  
  4.              
  5.  
  6.         Account[] accts = mgr.getAccountsByType("com.google");
  7.  
  8.         Account acct = accts[0];
  9.  
  10.         AccountManagerFuture<Bundle> accountManagerFuture =
  11.  
  12.                                                                 mgr.getAuthToken(acct, "ah", null, this, null, null);
  13.  
  14.         Bundle authTokenBundle = null;
  15.  
  16.        
  17.  
  18.         try {
  19.  
  20.                 authTokenBundle = accountManagerFuture.getResult();
  21.  
  22.         } catch (OperationCanceledException e) {
  23.  
  24.                 e.printStackTrace();
  25.  
  26.         } catch (AuthenticatorException e) {
  27.  
  28.                 e.printStackTrace();
  29.  
  30.         } catch (IOException e) {
  31.  
  32.                 e.printStackTrace();
  33.  
  34.         }
  35.  
  36.  
  37.  
  38.         String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();        
  39.  
  40.         Log.v(TAG, "authToken = " + authToken);
  41.  
  42.  
Parsed in 0.022 seconds, using GeSHi 1.0.8.4


I was thinking I could just send this authToken to GDocs but I'm seeing that GDocs wants to see a username and password sent to them, and then THEY issue an authToken that I then send back to them on subsequent calls.

So I modified my code to try and access the username and password of the user:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         Account[] accts = mgr.getAccountsByType("com.google");
  3.  
  4.         Account acct = accts[0];
  5.  
  6.         AccountManagerFuture<Bundle> accountManagerFuture =
  7.  
  8.                                                                 mgr.getAuthToken(acct, "ah", null, this, null, null);
  9.  
  10.         Bundle authTokenBundle = null;
  11.  
  12.         String username = mgr.getUserData(acct, mgr.KEY_USERDATA);
  13.  
  14.         String password = mgr.getPassword(acct);
  15.  
  16.         Log.v(TAG,"username = " + username);
  17.  
  18.         Log.v(TAG,"password = " + password);
  19.  
  20.        
  21.  
  22.                 try {
  23.  
  24.                         authTokenBundle = accountManagerFuture.getResult();
  25.  
  26.                 } catch (OperationCanceledException e) {
  27.  
  28.                         e.printStackTrace();
  29.  
  30.                 } catch (AuthenticatorException e) {
  31.  
  32.                         e.printStackTrace();
  33.  
  34.                 } catch (IOException e) {
  35.  
  36.                         e.printStackTrace();
  37.  
  38.                 }
  39.  
  40.         String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();        
  41.  
  42.         Log.v(TAG, "authToken = " + authToken);
  43.  
  44.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


I then break with the following exception:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Caused by: java.lang.SecurityException: caller uid 10072 is different than the authenticator's uid
  3.  
  4.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


I'm using AccountManager.getPassword(acct) and AccountManager.getUserData(acct, mgr.KEY_USERDATA) to get this and I don't know if this is right either.

I can see how GDocs wants you to connect to them but I can't see how to do it with the AccountManager tools that Android is giving us. I'm stuck and it stinks..

Any ideas?
emooney
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jan 26, 2010 11:03 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests