Gmail API: Insufficient Permission


I am testing the Gmail API for my app.

I have tested some requests and they are working fine.
For example get messages, get user history, get draft list etc..

Basically all the read only requests are working fine.

I have instead some issues related with permission with other requests, for example when i have to write or delete a draft.

This is the error i get:

(403) Insufficient Permission


This is the function to initialize the app:

public function gmail_init_service()
    $client = new Google_Client();

    $client->setApplicationName("Gmail API test");

    $service = new Google_Service_Gmail($client);

    return $service;

This is the 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' );


I have tried to revoke the permission and setup new credentials.
The scope declared when initializing the service is:

that as stated in the documentation grant full access to the account.

But i am still getting the same error.
The same exact error for the following requests:

Delete draft – Create draft – Create label – Delete message


Why am i getting that error?
It has to do with same values store in a cache?
Or is related with permission of the API?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You need ‘‘ to create a draft. So what happens if you


or if you want to get more formal

define('SCOPES', implode(' ', array(


or whatever the valid php might be (I haven’t done php for a while).

Note that if you have a token already you might have to do some calisthenics to revoke it so you can reissue with the added permissions. That might mean deleting a file, perhaps named or, if you have access to the account login and make your way to the access permissions can be manually revoked.

This link might be relevant:

And a meander through the source code might be enlightening.

You might be able to glean some insight from my battle with this same sort of thing under Python

Solution 2

You need as your scope to be able to delete mail.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply