在使用google-api-php-client庫上傳離線轉化到DoubleClick Search時遇到以下錯誤。使用google-api-php-client在DoubleClick Search API中遇到空批次錯誤
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "requestValidation", "message": "The request was not valid. Details: [Empty batch encountered.]" } ], "code": 400, "message": "The request was not valid. Details: [Empty batch encountered.]" } } ' in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/ds3/vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Array) #3 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #4 /var/www/ds3/vendor/google/apiclient/src/Google/Client.php(788) in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php on line 118
使用下面的代碼中插入新的轉換
putenv('GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_SERVICE_ACCOUNT_JSONFILE.json');
$Client = new Google_Client();
$Client->useApplicationDefaultCredentials();
$Client->addScope(Google_Service_Doubleclicksearch::DOUBLECLICKSEARCH);
$DS3 = new Google_Service_Doubleclicksearch($Client);
$Conversion = new Google_Service_Doubleclicksearch_Conversion();
$Conversion->setClickId('MY_GCLID');
$Conversion->setConversionId('MY_CONV_ID');
$Conversion->setConversionTimestamp('MY_CONV_TIMESTAMP');
$Conversion->setSegmentationType('FLOODLIGHT');
$Conversion->setSegmentationName('MY_FLOODLIGHT_ACTIVITY_NAME');
$Conversion->setSegmentationType('ACTION');
$ConversionList = new Google_Service_Doubleclicksearch_ConversionList();
$ConversionList->setConversion($Conversion);
$Response = $DS3->conversion->insert($ConversionList);
print_r($Response);
鏈接回到https://github.com/google/google-api-php-client/issues/1213 – DaImTo