请求的范围不允许 [英] Requested scopes not allowed

查看:195
本文介绍了请求的范围不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从 Google Directory API 获取用户,并使用以下请求:

I'm trying to fetch a user from Google Directory API with the following request:

Collection<String> SCOPES = Arrays.asList("https://www.googleapis.com/auth/admin.directory.user.readonly", "https://www.googleapis.com/auth/admin.directory.user");
URL url = getClass().getResource("privatekey.p12");
GoogleCredential credential = new GoogleCredential.Builder()
    .setJsonFactory(request.getJsonFactory())
    .setServiceAccountId("foobar.com")
    .setServiceAccountScopes(SCOPES)
    .setTransport(new NetHttpTransport())
    .setServiceAccountUser("foo@bar.com")
    .setServiceAccountPrivateKeyFromP12File(new File(url.getPath())).build();
Directory dir = new Directory.Builder(GoogleNetHttpTransport.newTrustedTransport(), request.getJsonFactory(), credential)
    .setApplicationName(request.getApplicationName())
    .build();

但是我从API中收到以下错误:

But I'm getting the following error from the API:

Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "access_denied",
  "error_description" : "Requested scopes not allowed: https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.user.readonly"
}

我检查过的范围是正确的,任何人都知道什么是问题在这里?

I've checked the scopes are correct, anyone know what's the problem here?

推荐答案

唉!我删除了旧的服务帐户并创建了一个新帐户。之后,事情开始滚动。猜测我有一个错误的p12文件等,终于可以呼吸了,唷。

Argh! I removed the old service account and created a new one. After that things started to roll. Guessing I had a wrong p12 file etc. Can finally breathe again, phew.

这篇关于请求的范围不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆