gmail.users.labels.list()功能.使用Google的Node.js API时,尝试发送电子邮件时出错.错误是:
{
"code": 403,
"errors": [{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}]
}
Run Code Online (Sandbox Code Playgroud)
fs.readFile(secretlocation, function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
authorize(JSON.parse(content), sendMessage);
});
function sendMessage(auth) {
var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', 'subject', 'message test');
gmail.users.messages.send({
auth: auth,
userId: 'me',
message: {
raw: raw
}
}, function(err, response) { …Run Code Online (Sandbox Code Playgroud) 我想使用Gmail API通过Python发送电子邮件.Everythings应该没问题,但我仍然得到错误"发生错误:b'Q29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PSJ1cy1hc2NpaSIKTUlNRS ..."这是我的代码:
import base64
import httplib2
from email.mime.text import MIMEText
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run_flow
# Path to the client_secret.json file downloaded from the Developer Console
CLIENT_SECRET_FILE = 'client_secret.json'
# Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.compose'
# Location of the credentials storage file
STORAGE = Storage('gmail.storage')
# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
# Try to retrieve …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 Python 中的 Google API 发送消息,并尝试运行几乎直接从Google 示例页面获取的示例。
def CreateMessage(sender, to, subject, message_text):
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string().replace('message','resource').encode('ascii'))}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试发送它时
message = CreateMessage(sender, to, subject, message_text)
message = service.users().messages().send(body=list(message),userId='me').execute()
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:“'raw' RFC822 有效负载消息字符串或通过 /upload/* URL 上传消息需要”
从其他帖子看来,谷歌似乎在期待一个附件。MIMEText 有什么问题让它期待一个,如果有,我该如何解决?