如何解决在 GMAIL API Get Calls 中传递变量值
所以我试图通过使用 GMAIL API 来获取消息。这样做需要我提供一个 messageID。我在本地列表中存储了几个消息 ID。但是,当我尝试将列表元素作为迭代传递给 GET 请求时,它只会将变量值用作字符串而不是变量本身。 有什么办法可以规避吗? IE。将 id='str(s) 替换为变量中的实际数字 '12345234534'
for s in ID_List:
req_result = service.users().messages().get(userId='me',id='str(s)').execute()
返回以下错误:
File "redacted",line 60,in main
req_result = service.users().messages().get(userId='me',id='str(s)').execute()
File "redacted\Python39\lib\site-packages\googleapiclient\_helpers.py",line 134,in positional_wrapper
return wrapped(*args,**kwargs)
File "redacted\Python\Python39\lib\site-packages\googleapiclient\http.py",line 915,in execute
raise HttpError(resp,content,uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://gmail.googleapis.com/gmail/v1/users/me/messages/str%28s%29?alt=json returned "Invalid id value". Details: "Invalid id value">
Gmail API 是否可能不允许我将变量作为查询字符串传递?
提前致谢!
解决方法
试试这个:
req_result = service.users().messages().get(userId='me',id=s).execute()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。