Gmail用户观看API PHP中出现500错误

时间:2018-06-05 07:11:41

标签: php codeigniter gmail-api php-7

我已经在Cloud Pub / Sub上设置了主题和订阅,现在我试图在我的Gmail帐户上设置监视但由于某种原因,我得到了(500) Backend Error

以下是我使用的代码:

$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);
}  

我得到了低于回应:

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

有人可以指导我吗?

1 个答案:

答案 0 :(得分:0)

我自己解决了。

任何人如果遇到此问题,请向gmail-api-push@system.gserviceaccount.com授予发布商权限,并且该权限应该有效。