【发布时间】:2014-03-13 14:56:28
【问题描述】:
我使用下面的sn-p来获取token:
private class task extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
Bundle appActivities = new Bundle();
appActivities.putString(
GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
Constants.ADD_ACTIVITY_SCHEME + " "
+ Constants.BUY_ACTIVITY_SCHEME);
String serverClientID = "My_Client_Id";
String scopes = "oauth2:server:client_id:" + serverClientID
+ ":api_scope:" + Scopes.PLUS_LOGIN + " "
+ Scopes.PLUS_PROFILE;
String code = null;
try {
code = GoogleAuthUtil.getToken(MainActivity.this, // Context
// context
mPlusClient.getAccountName(), // String accountName
scopes, // String scope
appActivities // Bundle bundle
);
} catch (IOException transientEx) {
code = "Loi 1";
} catch (UserRecoverableAuthException e) {
code = "Loi 2: "+e.getMessage();
} catch (GoogleAuthException authEx) {
code = "Loi 3";
} catch (Exception e) {
throw new RuntimeException(e);
}
return code;
}
@Override
protected void onPostExecute(String token) {
showToast(token);
}
}
我在 onConnected 方法中执行这行代码:
new task.execute();
UserRecoverableAuthException 发生并且我的 toast 显示消息:“NeedPermission”。
我该如何解决?
【问题讨论】:
-
我确实遵循@Rrthinavel 代码,我收到了这样的 id_token:ya29.1.AADtN_Wtc1xlFEILNL9aUdp98dE6yI...我将此 id_token 传递到 google url lis=ke this:googleapis.com/oauth2/v1/…...我收到一条消息: {"error": "invalid_token","error_description": "Invalid Value"} 我认为 getToken() 3 args 和 getToken() 4 args 之间可能存在差异。当我跟随你编码时,我得到令牌代码,但验证时无效。我通过上面的代码尝试代码,我得到一个例外:NeedPermission。请帮我!谢谢。
-
任何帮助。我需要解决这个问题。谢谢。
-
@Nguyen 试试这个网址:graph.facebook.com/me?access_token="Your 访问令牌"