【问题标题】:googleauthutil.gettoken times outgoogleauthutil.gettoken 超时
【发布时间】:2013-12-04 18:02:36
【问题描述】:

我有一个应用程序,我正在尝试在其中获取 google 身份验证令牌。它在每个请求上都会超时,并且在 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 天,并且正在竭尽全力试图解决这个问题。我知道它必须是简单的。我会接受任何想法。

【问题讨论】:

  • 我的项目中确实有多个应用程序具有不同的包名称和相同的调试密钥。这是我问题的根源吗?
  • 包名和sha键不是我问题的根源。我仍然不确定是什么。

标签: android google-app-engine authentication oauth


【解决方案1】:

这不是一个完整的答案,但我无法评论你的帖子,因为我必须先有 50 个声望,而我没有。


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

为避免超时问题,您必须更改执行任务的行 来自:

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

收件人:

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

无论您想对令牌做什么:

  • 在 doInBackground 方法中进行
  • 或在 doInBackground 中调用另一个方法并将令牌传递给该方法。

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

【讨论】:

  • 非常感谢。这正是我需要能够摆脱我的项目。不幸的是,我没有足够高的排名来支持你,但这篇文章对你有很大帮助。
猜你喜欢
  • 2015-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
  • 2014-01-31
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
相关资源
最近更新 更多