“权限不足"; Google Appscripts错误 [英] "Insufficient Permissions" Error with Google Appscripts

查看:82
本文介绍了“权限不足"; Google Appscripts错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用google appscripts创建草稿时出现以下错误

I get following error when I try to create draft using google appscripts

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientPermissions",
    "message": "Insufficient Permission"
   }
  ],
  "code": 403,
  "message": "Insufficient Permission"
 }
}

我在资源->高级Google服务中启用了GMAIL api服务.我正在使用以下端点来创建草稿.

I enabled GMAIL api service in resource --> Advanced google services. I am using the following end point to create the draft.

https://www.googleapis.com/gmail/v1/users/我/草稿

我不确定是否需要启用其他任何api才能使其正常工作.希望能帮助您调试此问题

I am not sure if I need to enable any other api to make this work. Would appreciate any help to debug this issue

我正在制作如下所示的api:

I am making the api as shown below:

function createDraft(tid,Subject,Body,fromEmail,toEmail,ccEmail) {

var boundary = "ABDADASFDSBCCCADSAD" + (new Date()).getTime().toString();

SendSubject = "Subject:" + Subject

raw = SendSubject + "\r\n" + 
"From: " + fromEmail +  "\r\n" +
"To: " + toEmail +  "\r\n" +
"Cc: " + ccEmail +  "\r\n" +
"Content-Type: multipart/alternative; boundary=" + boundary  + "\r\n" + "\r\n" + 
"--" + boundary + "\r\n" +
"Content-Type: text/html; charset=UTF-8" + "\r\n" + 
"Content-Transfer-Encoding: quoted-printable"  + "\r\n" + "\r\n" + 
  Body + "\r\n" + "\r\n" + 
 "--" + boundary + "--"
//var draftBody = Utilities.base64Encode(raw, Utilities.Charset.US_ASCII).replace(/\//g,'_').replace(/\+/g,'-')

var draftBody = Utilities.base64EncodeWebSafe(raw,  Utilities.Charset.UTF_8)


var params = {method:"post",
                contentType: "application/json",
                headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken(),  "Reply-To": "naveen@skedool.it"},
                muteHttpExceptions:true,
                payload:JSON.stringify({
                  "message": {
                    "raw": draftBody,
                    "threadId" : tid
                  }
                })
               };

 var resp = UrlFetchApp.fetch("https://www.googleapis.com/gmail/v1/users/me/drafts", params);
 //Logger.log(resp);


return resp

}

推荐答案

您收到的错误与凭据有关.尽管您正在发送令牌,但该令牌无权访问Gmail.

The error you are getting is related to the credentials. although you are sending a token, that token does not have access to Gmail.

在Apps脚本中,转到菜单资源>高级Google服务"

In Apps script go to the menu "Resources > Advances Google Services"

找到Gmail服务并启用它.

There look for the Gmail service and enable it.

然后单击文本链接还必须在Google Developers Console中启用这些服务."

Then click on the link of the text "These services must also be enabled in the Google Developers Console."

它将打开开发者控制台,并且您还必须在其中启用Gmail API.

It will open the Developer Console, and also there you have to enable the Gmail API.

这样做之后,再次运行您的代码,它将要求访问Gmail的权限. 现在,令牌将可以访问Gmail API.

After doing that, run your code again and it will ask for permission to access Gmail. Now the token will have access to Gmail API.

让我知道它是否对您不起作用.

Let me know if it didn't work for you.

这篇关于“权限不足"; Google Appscripts错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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