Android 403谷歌任务API错误
我试图对GoogleTasksAPI进行REST调用,但它总是返回以下内容Android 403谷歌任务API错误,android,rest,google-tasks-api,Android,Rest,Google Tasks Api,我试图对GoogleTasksAPI进行REST调用,但它总是返回以下内容 { "error": { "errors": [ { "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured. The API (Tasks API) is not enabled for your project. Please use the Googl
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API (Tasks API) is not enabled for your project. Please use the Google Developers Console to update your configuration.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "Access Not Configured. The API (Tasks API) is not enabled for your project. Please use the Google Developers Console to update your configuration."
}
}
这是我的代码,范围是oauth2:
第二部分,GoogleSync是一个AsyncTask,在doInBackground中调用getTaskList()
private void getTasksListFromGoogle() {
if (mEmail == null) {
pickUserAccount();
} else {
if (Utility.IsNetworkEnable(this)) {
new GoogleSync(this, mEmail).execute();
} else {
Toast.makeText(this, R.string.noNetwork, Toast.LENGTH_LONG).show();
}
}
}
private void pickUserAccount() {
String[] accountTypes = new String[]{StaticValue.COM_GOOGLE};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,accountTypes, false, null, null, null, null);
startActivityForResult(intent, StaticValue.REQUEST_CODE_PICK_ACCOUNT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == StaticValue.REQUEST_CODE_PICK_ACCOUNT) {
if (resultCode == RESULT_OK) {
mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
getTasksListFromGoogle();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.pick_account, Toast.LENGTH_SHORT).show();
}
}
}
public void handleException(final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
int statusCode = ((GooglePlayServicesAvailabilityException)e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode,MainActivity.this,StaticValue.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
Intent intent = ((UserRecoverableAuthException)e).getIntent();
startActivityForResult(intent,StaticValue.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
}
});
}
这是我的API控制台,com.kmconcept.googletasklist是我的包名
i、 stack.imgur.com/89zG0.png
i、 stack.imgur.com/paKgr.png
我猜oauth2有点问题,关键是使用了debugkey,希望有人能给出任何想法。谢谢启用您的Google任务API。它在您的API中&auth
尝试使用浏览器键,而不是android键盘操作系统?有任何样本可供参考吗?请问您是如何在这里获得您的令牌的
https://www.googleapis.com/tasks/v1/users/@me/lists?access_token=“+token
我从GoogleAuthUtil.getToken(mActivity,mEmail,StaticValue.SCOPE2)获得它;String SCOPE2=“oauth2:”;public static final String SCOPE2=“oauth2:”;mEmail来自pickUserAccount()
private void getTasksListFromGoogle() {
if (mEmail == null) {
pickUserAccount();
} else {
if (Utility.IsNetworkEnable(this)) {
new GoogleSync(this, mEmail).execute();
} else {
Toast.makeText(this, R.string.noNetwork, Toast.LENGTH_LONG).show();
}
}
}
private void pickUserAccount() {
String[] accountTypes = new String[]{StaticValue.COM_GOOGLE};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,accountTypes, false, null, null, null, null);
startActivityForResult(intent, StaticValue.REQUEST_CODE_PICK_ACCOUNT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == StaticValue.REQUEST_CODE_PICK_ACCOUNT) {
if (resultCode == RESULT_OK) {
mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
getTasksListFromGoogle();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.pick_account, Toast.LENGTH_SHORT).show();
}
}
}
public void handleException(final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
int statusCode = ((GooglePlayServicesAvailabilityException)e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode,MainActivity.this,StaticValue.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
Intent intent = ((UserRecoverableAuthException)e).getIntent();
startActivityForResult(intent,StaticValue.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
}
});
}