2
votes

I have setup Topic and Subscription on Cloud Pub/Sub and now i m trying to set watch on my gmail account but for some reason, i m getting (500) Backend Error.

Below is the code i m using:

$client = new Google_Client();
$client->setClientId('google_client_id');
$client->setClientSecret('google_client_secret');
$client->setRedirectUri('google_redirect_url');
$client->addScope("https://mail.google.com/");
$client->setAccessType("offline");
$client->setApprovalPrompt('force');
$service = new Google_Service_Gmail($client);
try {
    $watch = new Google_Service_Gmail_WatchRequest($client);
    $watch->setTopicName("projects/project-id/topics/topic-id");
    $messagesResponse = $service->users->watch("me", $watch, array("topicName" => "projects/project-id/topics/topic-id"));
} catch(Exception $e) {
    print_r($e);
}  

I m getting below response :

Array
(
    [userId] => me
    [postBody] => Google_Service_Gmail_WatchRequest Object
        (
            [collection_key:protected] => labelIds
            [labelFilterAction] => 
            [labelIds] => 
            [topicName] => projects/project-id/topics/topic-id
            [internal_gapi_mappings:protected] => Array
                (
                )

            [modelData:protected] => Array
                (
                )

            [processed:protected] => Array
                (
                )

        )

    [topicName] => projects/project-id/topics/topic-id
)

Google_Service_Exception Object
(
    [errors:protected] => Array
        (
            [0] => Array
                (
                    [domain] => global
                    [reason] => backendError
                    [message] => Backend Error
                )

        )

    [retryMap:Google_Service_Exception:private] => Array
        (
            [500] => -1
            [503] => -1
            [rateLimitExceeded] => -1
            [userRateLimitExceeded] => -1
        )

    [message:protected] => Error calling POST https://www.googleapis.com/gmail/v1/users/me/watch: (500) Backend Error

Can anyone guide me please?

1

1 Answers

1
votes

I solved it myself.

Anyone who is getting this issue, grant publisher rights to [email protected] and it should work.