3

I am using gmail api to modify some label for a certain message below

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

but the google developer in https://developers.google.com/gmail/api/v1/reference/users/messages/modify did not state the need to pass in the access token, how do I pass the access token to the api to modify the label for the messsage?

Rgds

Vincent

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
pjsiong
  • 181
  • 1
  • 6
  • Possible duplicate of [How are parameters sent in an HTTP POST request?](http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request) – Linda Lawton - DaImTo Feb 16 '16 at 13:26

1 Answers1

2

You could either put it in a query parameter:

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

Or in the Authorization header:

POST https://www.googleapis.com/gmail/v1/users/userId/messages/id/modify
Authorization: Bearer {ACCESS_TOKEN}
Tholle
  • 108,070
  • 19
  • 198
  • 189
  • Actually my problem is the documentation in https://developers.google.com/gmail/api/v1/reference/users/messages/modify do not have clear indication on how to call this api, not sure if it using access token or api key> – pjsiong Feb 17 '16 at 01:08
  • @pjsiong Ah, I see. The key can be used to try your own mail if I'm not mistaking. I have never tried that. You will have to use the `access token` of your real users later though. You can authorize with the Gmail API scopes at the [Oauth Playground](https://developers.google.com/oauthplayground/) and use that for testing. – Tholle Feb 17 '16 at 01:28
  • Hi, I tried in the playground and it return with below error 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 Host: www.googleapis.com Content-length: 34 Content-type: application/json { "removeLabelIds": [ "UNREAD" ]} – pjsiong Feb 17 '16 at 07:54
  • HTTP/1.1 401 Unauthorized Content-length: 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, 17 Feb 2016 07:52:45 GMT X-frame-options: SAMEORIGIN Content-type: application/json; charset=UTF-8 Www-authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token – pjsiong Feb 17 '16 at 07:55
  • { "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "locationType": "header", "domain": "global", "message": "Invalid Credentials", "reason": "authError", "location": "Authorization" } ] } } – pjsiong Feb 17 '16 at 07:55
  • @pjsiong Just give the `access_token` once. – Tholle Feb 17 '16 at 13:03