我正在尝试创建一个允许用户将自己作为所有者添加到日历的网络应用。我正在尝试在日历的ACL中插入新规则,但是我无法获得使用Calendar API的权限。
在我授权脚本运行弹出的对话框后,我收到以下错误消息:“无法对服务进行身份验证:日历。”
我做错了什么?
function insertRule() {
ScriptApp.invalidateAuth();
var calId = MY_CAL_ID;
var userEmail = Session.getActiveUser().getEmail();
var API_KEY = MY_API_KEY;
var apiName = 'calendar';
var scope = 'https://www.googleapis.com/auth/calendar';
var fetchArgs = googleOAuth_(apiName, scope);
fetchArgs.method = "POST";
var payload =
{
"role" : "owner",
"scope" :
{
"type" : "user",
"value" : userEmail
}
};
fetchArgs.payload = payload;
var base = 'https://www.googleapis.com/calendar/v3/calendars/';
var url = base + calId + '/acl?key=' + API_KEY;
var response = UrlFetchApp.fetch(url, fetchArgs).getContentText();
}
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("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
答案 0 :(得分:1)
我有同样的问题。 我在下面找到了链接,但客户端是scripts.google.com?希望它会让我们指出正确的方向。
http://googleappsdeveloper.blogspot.ca/2011/12/calendar-api-v3-2-legged-oauth-java.html