vlad-ardelean
vlad-ardelean

Reputation: 7622

Google APIs (gmail and spreadsheet): what more should I set up, or to know what setup I'm missing?

I'm creating a webapp, that includes some cron jobs, which would call the gmail API, and the google spreadsheet API.

I've created a project in my google developers deashboard, and credentials for it, to use with my app.

I've also enabled the Gmail API and the Google Sheets API in the console.

I'm using the Python library, and calling both APIs fails.

For example, the spreadsheet service throws this error:

/home/vardelean/work/connect-app/ty/connect/commands/populate_matching_spreadsheet.pyc in iterate_google_spreadsheet(document_id, spreadsheet_service)
    300         unmatched_hotels_document = spreadsheet_service.values().get(
    301                         spreadsheetId=document_id,
--> 302                         range='Sheet1'
    303         ).execute()["values"]
    304                 header = unmatched_hotels_document[0]

/home/vardelean/ve/connect/local/lib/python2.7/site-packages/oauth2client/util.pyc in positional_wrapper(*args, **kwargs)
    135                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    136                     logger.warning(message)
--> 137             return wrapped(*args, **kwargs)
    138         return positional_wrapper
    139 

/home/vardelean/ve/connect/local/lib/python2.7/site-packages/googleapiclient/http.pyc in execute(self, http, num_retries)
    830       callback(resp)
    831     if resp.status >= 300:
--> 832       raise HttpError(resp, content, uri=self.uri)
    833     return self.postproc(resp, content)
    834 

HttpError: <HttpError 403 when requesting https://sheets.googleapis.com/v4/spreadsheets/...document id here...../values/Sheet1?alt=json returned "The caller does not have permission">

I don't know what's meant with this lack of permissions. I tried to access the file while logged in as that user, and I do have edit rights to it. I also enabled the Google spreadsheets API, as stated.

And the Gmail service this one:

File "/home/vardelean/work/connect-app/ty/connect/commands/vwh_test_google_apis.py", line 31, in <module>
    main()
  File "/home/vardelean/work/connect-app/ty/connect/commands/vwh_test_google_apis.py", line 23, in main
    for message_meta in message_list.execute().get('messages', []):
  File "/home/vardelean/ve/connect/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/vardelean/ve/connect/local/lib/python2.7/site-packages/googleapiclient/http.py", line 832, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=INBOX&alt=json returned "Mail service not enabled">

...I don't know what is meant by "Mail service not enabled", since I did enable it in the development console.

Also, I checked what error I'd get with an empty credentials file (for example), and at least for the gmail service, it's some other error, so the credentials must be good to some extent. That error is RuntimeError: Couldn't authorise with the crentials stored at //path/to/bad/credentials/file

Can anyone help on this?

Upvotes: 1

Views: 375

Answers (1)

Teyam
Teyam

Reputation: 8092

You may want to try setting isMailboxSetup to true as mentioned in this thread and also commented in this SO post.

As mentioned in the given reference:

isMailboxSetup indicates if the user's Google mailbox is created. This property is only applicable if the user has been assigned a Gmail license.

Upvotes: 1

Related Questions