googleauthutil.gettoken超时

时间:2013-11-20 16:16:06

标签: android google-app-engine authentication oauth

我有一个应用程序,我正在尝试获取谷歌身份验证令牌。它会在每个请求上超时,并且在logcat中没有提供有用的消息。我试图弄清楚我是否未能正确设置云控制台或者我的代码存在问题。

我的令牌请求类:

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";



   }

我调用它的方法:

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();

            }

      }
}

我的相关清单设置                               

我会发布我的logcat,但我得到的只是println告诉我我正在使用的上下文,电子邮件和范围,然后错误告诉我我的活动超时。我没有收到任何回复。感谢您的回复,我现在已经研究了这个不停的5天,并且在我的智慧结束时试图解决这个问题。我知道它必须是简单的东西。我会接受任何想法。

1 个答案:

答案 0 :(得分:4)

这不是一个完整的答案,但我无法对你的帖子发表评论,因为我必须首先获得50个声誉,但我没有。


我目前遇到与GoogleAuthUtil.getToken(...)不同的问题。 但是当我尝试执行任务的方法时,我的超时问题可能和你的一样。

要避免超时问题,您必须更改执行任务的行 从:

token=new GetMyToken(getApplicationContext()).execute(accountEmail).get();

要:

new GetMyToken(getApplicationContext()).execute(accountEmail);

无论您想要使用令牌,还是:

  • 在doInBackground方法中执行此操作
  • 或调用doInBackground中的另一个方法并将标记传递给该方法。

doInBackground在后台运行,您不应该挂起应用程序等待其响应。 这样做可以防止超时问题,并让我回到我已经面临的问题。