簡體   English   中英

Guzzle將HTTP請求發送到Google API,服務器500錯誤

[英]Guzzle Sends HTTP request to Google API, server 500 error

我使用Guzzle將HTTP請求發送到Gmail API

這部分一直導致服務器500錯誤,為什么?

$data = new stdClass; 
$data-> 'topicName' ='projects/sample.com:sample/topics/topic';   
$data-> 'labelIds' = ["INBOX"];
$data-> 'labelFilterAction' = 'include'; 

完整代碼:

    require_once __DIR__.'/vendor/autoload.php';
    $client = new Google_Client();
    $client->setScopes("https://www.googleapis.com/auth/gmail.readonly");
    putenv('GOOGLE_APPLICATION_CREDENTIALS=sample.json');
    $client->useApplicationDefaultCredentials();
    // returns a Guzzle HTTP Client
    $httpClient = $client->authorize();
    $data = new stdClass; 
    $data->'topicName' ='projects/sample.com:sample/topics/topic';   
    $data-> 'labelIds' = ["INBOX"];
    $data-> 'labelFilterAction' = 'include';
    $request = new GuzzleHttp\Psr7\Request('POST', 'https://www.googleapis.com/gmail/v1/users/post@sample.com/watch',['Content-type'=>'application/json'],$data);
    $response = $httpClient->send($request);

    var_dump($response);

$ data對象的屬性周圍不應包含單引號。

它應該是:

$data->topicName ='projects/sample.com:sample/topics/topic';   
$data->labelIds = ["INBOX"];
$data->labelFilterAction = 'include';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM