我已经阅读了Admin ADK Directory API 文档中的所有相关页面以及有关 stackoverflow 的几个问题,但我仍然卡住了。
我正在尝试使用 Google Apps 脚本(Google 表格的脚本编辑器中的容器绑定)来创建一个组。我是我的 Google Apps 域的超级管理员,脚本将以我的身份运行。
到目前为止,这是我在脚本编辑器中所做的:
前往资源 - 高级 Google 服务... - 打开 Admin Directory API
单击 Google Developers Console 下方的链接并启用 Admin SDK
使用了我用来设置用户电子邮件签名的工作代码(改编自这篇博客文章,并对其进行了修改以创建组:
function createGroupTest() { var t = new Date(); t = t.getTime(); createGroup("AAA Test Group " + t, "aaa.testgroup." + t + "@mydomain.com" , "test@mydomain.com", "test"); } function createGroup(groupName,groupEmail,owner,description) { var requestBody = '{"email": "'+groupEmail+'","name": "'+groupName+'","description": "'+description+'"}'; var scope="https://www.googleapis.com/auth/admin.directory.group"; var fetchArgs=googleOAuth_("Groups",scope); fetchArgs.method="POST"; fetchArgs.contentType="application/json"; fetchArgs.payload=requestBody; var url = 'https://www.googleapis.com/admin/directory/v1/groups'; UrlFetchApp.fetch(url, fetchArgs); } function googleOAuth_(name,scope) { var oAuthConfig = UrlFetchApp.addOAuthService(name) oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oAuthConfig.setConsumerKey(consumerKey); oAuthConfig.setConsumerSecret(consumerSecret); return {oAuthServiceName:name, oAuthUseToken:'always'}; }
当我运行它时,我得到以下响应:
Request failed for returned code 403. Truncated server response: { "error": { "errors": [ { "domain": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "Daily Limit for Unauthentica... (use muteHttpExceptions option to examine full response) (line 60, file "Main")
当我添加fetchArgs.muteHttpExceptions=true;
错误输出更改为Failed to authenticate for service: Groups
.