Google Admin SDK 403未授权访问此资源/ API [英] Google Admin SDK 403 Not Authorized to Access this Resource/API

查看:227
本文介绍了Google Admin SDK 403未授权访问此资源/ API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java web应用程序中使用以下代码尝试获取组的所有用户:

  GoogleCredential凭证= GoogleCredential.fromStream(Util.class.getResourceAsStream( [credential_file]上传.json))createScoped(范围)。 

目录目录= new Directory.Builder(httpTransport,JSON_FACTORY,凭证).build();

Directory.Members dirMem = directory.members();
成员成员= dirMem.list([group_email])。execute();

这会导致最后一行发生异常403(无权访问此资源/ API) dirMem.list ...)。



从文档( https://developers.google.com/admin-sdk/directory/v1/guides/delegation )和其他职位,我看到解决方案是使用 setServiceAccountUser()来设置服务帐户用户。
但是,这意味着我必须使用p12文件而不是json文件(Google建议您在创建密钥时使用json文件)。



有没有办法在仍使用json文件的情况下解决此问题(它也涉及较少的代码)。



谢谢。 现在,我只是使用p12文件,如下所示:



https://developers.google。如果有人知道用json文件在这个问题中执行代码的方法,那么你可以使用json文件,随时评论/回答。


I use the following code in a java web application to try to get all users of a group:

GoogleCredential credential = GoogleCredential.fromStream(Util.class.getResourceAsStream("[credential_file].json")).createScoped(SCOPES);

Directory directory = new Directory.Builder(httpTransport, JSON_FACTORY, credential).build();

Directory.Members dirMem = directory.members();
Members members = dirMem.list("[group_email]").execute();

This results in an exception 403 (Not authorized to access this resource/API) on the last line (dirMem.list...).

From the documentation (https://developers.google.com/admin-sdk/directory/v1/guides/delegation) and other posts, I saw that the solution to this is to set a service account user with setServiceAccountUser(). However, this means that I have to use a p12 file instead of a json file (Google recommends using a json file when you create the key).

Is there any way to get around this issue while still using a json file (it also involves less code).

Thanks.

解决方案

For now, I am just using the p12 file as outlined here:

https://developers.google.com/admin-sdk/directory/v1/guides/delegation

If anyone knows of a way to execute the code in this question with a json file, feel free to comment/answer.

这篇关于Google Admin SDK 403未授权访问此资源/ API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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