我正在尝试使用GoogleAuthUtil获取令牌,以便我可以在后端验证请求。
我只使用了AccountManager.newChooseAccountIntent()
private void pickUserAccount() {
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
}
这是onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
if (resultCode == RESULT_OK) {
mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
new VerifyToken().execute(mEmail);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "You need to select account.", Toast.LENGTH_SHORT).show();
finish();
}
}
}
AsyncTask:
class VerifyToken extends AsyncTask<String, Void , String>{
String mScope = "audience:server:client_id:X";
@Override
protected String doInBackground(String... strings) {
try{
String token = GoogleAuthUtil.getToken(getApplicationContext(), strings[0] ,mScope );
这是错误日志: