Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get messages from Gmail via HTTPS GET call

I'm working on an iOS application and what I'd like to do is have the app ping one universal Gmail account to check for the most recent email.

I went through the guide from Google at https://developers.google.com/gmail/api/quickstart/ios?ver=swift, but the result did not work. After some googling, it appears that some functionality may have been changed, but they haven't updated their documentation yet.

Is there a way to send credentials via https to Gmail and get email messages back? I have an OAuth key via the Gmail API manager, but when I pass it as "access_token", the response says "Login Required".

like image 786
Ryan Avatar asked Feb 03 '17 04:02

Ryan


1 Answers

AFAIK, an error response "Login Required" can be encountered if you try to list the buckets for a project that do not provide an authorization header.

If we check Users.messages: get, it's noted that it requires authorization.

For this, you may want to check Authorizing Your App with Gmail wherein you will find these basic authorization pattern:

  1. During development, register the application in the Google API Console.
  2. When the app launches, request that the user grant access to data in their Google account.
  3. If the user consents, your application requests and receives credentials to access the Gmail API.
  4. Refresh the credentials (if necessary).

Furthermore, if your application needs to access Google APIs on behalf of the user, you should use server-side flow. Please see Implementing Server-Side Authorization for more information.

like image 53
Teyam Avatar answered Sep 18 '22 07:09

Teyam