Java 试图通过Google API获取刷新令牌时获取无效的\u作用域
我似乎无法在Oauth中使用GoogleAPI。我错过了什么 错误消息:Java 试图通过Google API获取刷新令牌时获取无效的\u作用域,java,api,oauth,gmail,Java,Api,Oauth,Gmail,我似乎无法在Oauth中使用GoogleAPI。我错过了什么 错误消息: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request { "error" : "invalid_scope", "error_description" : "Invalid oauth scope or ID token audience provided." } Java代码: com.google.api.clien
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_scope",
"error_description" : "Invalid oauth scope or ID token audience provided."
}
Java代码:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_scope",
"error_description" : "Invalid oauth scope or ID token audience provided."
}
私有void打印标签(){
HttpTransport-HttpTransport=GoogleNetHttpTransport.newTrustedTransport();
JsonFactory JsonFactory=JacksonFactory.getDefaultInstance();
列表范围=新的ArrayList();
添加(GmailScopes.GMAIL_标签);
GoogleCredential credential=GoogleCredential.fromStream(新文件输入流(“C:\\test\\credential.json”);
createScoped(范围);
credential.refreshtToken();//此处发生错误
字符串appName=“VS”;
Gmail.Builder=新的Gmail.Builder(httpTransport、jsonFactory、凭证)
.setApplicationName(appName);
Gmail=builder.build();
对象o=gmail.users().labels().list(“me”).execute();
System.out.println(“o=”+o);
}
谷歌API配置:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_scope",
"error_description" : "Invalid oauth scope or ID token audience provided."
}
您尝试执行的操作有点不清楚,并且此代码不完整。据说刷新令牌是自动处理的。您好@ChristopherSchneider,谢谢您的回复。我用我一直使用的其他代码更新了我的问题。这是我第一次尝试使用谷歌API,所以我的目标只是打印标签。在你看来,我试图跳过refreshToken()调用,因为Google会自动处理,但在调用execute()时,却得到了同样的错误。你有没有看到我遗漏或做错的其他东西?我对revolution/laravel google sheets也有同样的问题,你找到解决方案了吗?@Mahefa你可以在你的google中添加“scopes”=>[google\u Service\u sheets::DRIVE,google\u Service\u sheets::SPREADSHEETS]config@keatweithks,我来测试一下