Skip to content
Advertisement

Gmail API Signature Server Side

I want to change all signatures from my Gmail domain. This domain has many accounts, and I need to change it from server-side.

I’m using php, and I started my project with: php composer.phar require google/apiclient:2.0

I wrote one code, but when I try to update one email (like teste@mydomain.com), I receive:

JavaScript

My code (using API client library) is something like:

JavaScript

My credential file (gmailAPI.json) is one service account key, and I’m using Google for Work.

I created this credential using one administrator account from this domain.

My credential file is:

JavaScript

Edit 1

I changed the scopes as instructed, and now my scopes are:

$client->setScopes([‘https://www.googleapis.com/auth/gmail.settings.basic‘,’https://www.googleapis.com/auth/gmail.settings.sharing‘]);

I also added permision on Google (/AdminHome?chromeless=1#OGX:ManageOauthClients) to my service account key.

I tried API explorer and it works. When i changed the scopes, the error changed to:

{ “error”: { “errors”: [ { “domain”: “global”, “reason”: “failedPrecondition”, “message”: “Bad Request” } ], “code”: 400, “message”: “Bad Request” } }

I’m using this command:

var_dump($gmail->users_settings_sendAs->update(“someEmail@myDomain.com.br”,”someEmail@myDomain.com.br”,$signature));

I tried also

var_dump($gmail->users_settings_sendAs->get(“someEmail@myDomain.com.br”,”someEmail@myDomain.com.br”));

But I received same error.

Advertisement

Answer

Thank You everyone.

I tried a lot of codes, and finally found one that works.

JavaScript

I commented all code, and I used https://developers.google.com/api-client-library/php/auth/service-accounts to create it.

Atention -> You need to give permission on Gmail, and create server key (with domain-wide access).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement