Reputation: 121
I have an app in which I'm attempting get a google authentication token. It times out on every request and gives no useful messages in logcat. I'm attempting to figure out if I've failed at setting up my cloud console properly or if I have some problem with my code.
My token request class:
public class GetMyToken extends AsyncTask<String,Void,String>{
Context c;
String TAG = "wnycmap issues";
public GetMyToken(Context c) {
this.c=c;
}
@Override
protected String doInBackground(String...mEmail) {
String mScope = "oauth2:https://www.googleapis.com/auth/plus.me";
String email = mEmail[0];
System.out.println(c+email+mScope);
try {
return GoogleAuthUtil.getToken(c, email, mScope);
// System.out.println(token);
} catch (IOException transientEx) {
// Network or server error, try later
Log.e(TAG, transientEx.toString());
} catch (UserRecoverableAuthException e) {
// Recover (with e.getIntent())
Log.e(TAG, e.toString());
// Intent recover = e.getIntent();
//startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
} catch (GoogleAuthException authEx) {
Log.e(TAG, authEx.toString());
}
return "nope";
}
My method that calls it:
private void authenticate() {
String accountEmail="asdf";
String token = "null";
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccountsByType("com.google");
if (accounts != null){
Account account = accounts[0];
accountEmail = account.name;
System.out.println(context);
try {
token=new GetMyToken(getApplicationContext()).execute(accountEmail).get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
And my relevant Manifest Settings
I would post my logcat but all I get is the println telling me the context, email, and scope I'm using followed by an error telling me that my activity timed out. I'm not receiving any reply. Thank you for any replies, I've been researching this non stop for 5 days now and am at the end of my wits trying to fix this problem. I know it has to be something simple. I'll take any ideas.
Upvotes: 2
Views: 941
Reputation: 41
This is not a complete answer, but I couldn't comment on your post because I have to have 50 reputations first, which I don't.
I'm currently having a different issue with GoogleAuthUtil.getToken(...). But when I tried your method of executing the task, I got a timeout issue probably the same as yours.
To avoid the timeout issue, you have to change the line that executes the task From:
token=new GetMyToken(getApplicationContext()).execute(accountEmail).get();
To:
new GetMyToken(getApplicationContext()).execute(accountEmail);
Whatever it is that you want to do with the token, either:
doInBackground runs in the background and you should not hang the application waiting for its response. Doing this prevented the timeout issue, and sent me back to the issue I was already facing.
Upvotes: 4