【问题标题】:How to post access token parameter to the Gmail api如何将访问令牌参数发布到 Gmail api
【发布时间】:2016-05-27 18:42:34
【问题描述】:

我正在使用 gmail api 修改下面某条消息的一些标签

POST https://www.googleapis.com/gmail/v1/users/userId/messages/id/modify

但是https://developers.google.com/gmail/api/v1/reference/users/messages/modify中的谷歌开发者 没有说明需要传入访问令牌,如何将访问令牌传递给api来修改消息的标签?

Rgds

文森特

【问题讨论】:

标签: http gmail-api


【解决方案1】:

你可以把它放在一个查询参数中:

POST https://www.googleapis.com/gmail/v1/users/userId/messages/id/modify?access_token={ACCESS_TOKEN}

或者在授权标头中:

POST https://www.googleapis.com/gmail/v1/users/userId/messages/id/modify
Authorization: Bearer {ACCESS_TOKEN}

【讨论】:

  • 其实我的问题是developers.google.com/gmail/api/v1/reference/users/messages/…中的文档没有明确说明如何调用这个api,不确定是使用access token还是api key>
  • @pjsiong 啊,我明白了。如果我没记错的话,该密钥可用于尝试您自己的邮件。我从来没有尝试过。不过,您稍后将不得不使用真实用户的access token。您可以在 Oauth Playground 处使用 Gmail API 范围进行授权,并将其用于测试。
  • 嗨,我试图在游乐场和它下面误差POST /gmail/v1/users/sndata%40abc.com/messages/152e915a67e36fdc/modify?access_token=ya29.iwKoFjRabp8JDVWZUaQPvTLzq-eQ7mERN91t4PEAz33432345IqHbkbQ0KmJzfkAu3nJQxA&access_token=ya29返回.iwLGVygU5zY3JPGAG7Yxqge-aYAb80yYZ432342343CTcHYMy40LAS_F2_Azl_Wwxb_q HTTP/1.1 主机:www.googleapis.com 内容长度:34 内容类型:application/json { "removeLabelIds": [ "UNREAD" ]}
  • HTTP/1.1 401 未经授权的内容长度:249 X-xss-protection:1; mode=block X-content-type-options: nosniff Expires: Wed, 17 Feb 2016 07:52:45 GMT Vary: Origin,X-Origin Server: GSE Cache-control: private, max-age=0 Date: Wed, 2016 年 2 月 17 日 07:52:45 GMT X-frame-options: SAMEORIGIN Content-type: application/json; charset=UTF-8 Www-authenticate: Bearer realm="accounts.google.com", error=invalid_token
  • { "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "locationType": "header", "domain": "global" , "message": "Invalid Credentials", "reason": "authError", "location": "Authorization" } ] } }
猜你喜欢
  • 2018-01-31
  • 2016-07-12
  • 2016-11-29
  • 2019-12-31
  • 2012-02-13
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
  • 2017-05-23
相关资源
最近更新 更多