SITUATION:
I am testing the Gmail API for my application.
I tested several queries and they work fine. For example, get messages, get user history, get a draft, etc.
Basically, all read-only requests work fine.
I have some issues related to resolving with other requests, for example, when I have to write or delete a draft.
This is the error I get:
(403) Insufficient Permission
CODE:
This is the application initialization function:
public function gmail_init_service() { $client = new Google_Client(); $client->setApplicationName("Gmail API test"); $client->setDeveloperKey("MY_KEY"); $client->setClientSecret('MY_CLIENT_SECRET'); $client->SetClientId('MY_CLIENT_ID'); $client->setScopes(array('https://mail.google.com/')); $client->setAccessToken('{"access_token":"MY_ACCESS_TOKEN","token_type":"Bearer","expires_in":3600,"refresh_token":"MY_REFRESH_TOKEN","created":1433502343}'); $service = new Google_Service_Gmail($client); return $service; }
This is a request to delete one draft:
public function gmail_delete_draft() { $service = $this->gmail_init_service(); // --------------- Get draft list -------------- $list = $service->users_drafts->listUsersDrafts('me'); $draftList = $list->getDrafts(); // --------------- Get draft IDs --------------- $inbox_draft = []; foreach($draftList as $mlist) { $draftId = $mlist->id; $optParamsGet2['format'] = 'full'; $single_message = $service->users_drafts->get('me', $draftId , $optParamsGet2); $inbox_draft[]['draftId'] = $draftId; $inbox_draft[]['draft'] = $single_message; } // --------------- Delete draft --------------- $draft_delete = $service->users_drafts->delete('me', 'DRAFT_ID' ); }
EDIT:
I tried to revoke permission and set new credentials. The scope declared at service initialization:
https:
as stated in the documentation, provide full access to the account.
But I still get the same error. Exact error for the following queries:
Delete draft - Create draft - Create label - Delete message
QUESTION:
Why am I getting this error?
Is this due to the same storage of values ββin the cache?
Or is it related to API permission?