$url = 'https://adwords.google.com/api/adwords/cm/v201809'; at the top in the 
code



вторник, 10 декабря 2019 г., 20:52:18 UTC+3 пользователь Василий Рогачев 
написал:
>
>
> Good afternoon!
>
> First time working with the Adwords API. Before that, I worked with 
> Google's Contats API and there were no problems. And here I do not quite 
> understand why the request is not fulfilled?
>
> The program code in php below. An example of a query took 
> https://developers.google.com/adwords/api/docs/guides/reporting . But I 
> do not quite understand why there is no refresh token in the request ?
>
> *502.* That’s an error.
>
> The server encountered a temporary error and could not complete your 
> request.
>
> <?php
> $params1='{
>    "reportDefinition": {
>        "selector": {
>            "fields": [
>                "Campaign",
>                "AdGroupId",
>                "Impressions",
>                "Clicks",
>                "Cost"
>            ],
>         "predicates": {
>                "field": "AdGroupStatus",
>            "operator": "IN",
>            "values": [
>                    "ENABLED",
>                    "PAUSED"
>                ]
>         }
>      },
>      "reportName": "Custom Adgroup Performance Report",
>      "reportType": "ADGROUP_PERFORMANCE_REPORT",
>      "dateRangeType": "LAST_7_DAYS",
>      "downloadFormat": "CSV",
>      "_xmlns": "https://adwords.google.com/api/adwords/cm/v201809";
>   }
> }';
> // Converts the input parameters of the query in JSON format
> $body = $params1;
>
> //print_r($body);
> //echo "<br>___________________________________________<br>";
>
>
> // Creating HTTP request headers
>
>
>
> $headers = array(
>    "Host: adwords.google.com",
>    "User-Agent: curl, gzip",
>    "Accept: /",
>    "Accept-Encoding: gzip",
>    "Authorization: Bearer ya29..................g",
>    "developerToken:NB....................Q",
>    "clientCustomerId:124...............li.apps.googleusercontent.com",
>    "Content-Length: 784",
>    "Expect: 100-continue",
>    "Content-Type: multipart/form-data; 
> boundary=------------------------12d01fae60c7b559",
> );
>
>
>
>
>
>
>
> echo " < br>Adwords Report<br>";
>
> // Curl initialization
> $curl = curl_init();
> curl_setopt($curl, CURLOPT_URL, $url);
> curl_setopt($curl, CURLOPT_POST, true);
> curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
>
> /*
> To fully use the https Protocol, you can enable SSL certificate 
> verification of the direct API server.
> To enable validation, set the CURLOPT_SSL_VERIFYPEER option to true, and 
> uncomment the string with the CURLOPT_CAINFO option and specify the path to 
> the local copy of the root SSL certificate.
> */
> curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
> // curl_setopt($curl, CURLOPT_CAINFO, getcwd().'\CA.pem');
>
> curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
> curl_setopt($curl, CURLOPT_HEADER, true);
> curl_setopt($curl, CURLINFO_HEADER_OUT, true);
> curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
>
> // - - - Run a loop to execute queries ---
> // If HTTP code 200 is received, the report content is displayed
> // If HTTP code 201 or 202 is received, repeated requests are made
> while (true) {
>
>     $result = curl_exec($curl);
>
>     if (!$result) {
>
>         echo ('curl error:'.curl_errno($curl).'- ' .curl_error($curl));
>
>         break;
>
>     } else {
>
>         // Separation of HTTP headers and the response body
>        $responseHeadersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
>        $responseHeaders = substr($result, 0, $responseHeadersSize);
>        $responseBody = substr($result, $responseHeadersSize);
>
>         // Get HTTP status code
>        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
>
>         // Retrieving HTTP response headers
>        // Request ID
>        $requestId = preg_match('/RequestId: (\d+)/', $responseHeaders, 
> $arr)? $arr[1]: false;
>        // Recommended interval in seconds to check if the report is ready
>        $retryIn = preg_match('/retryIn: (\d+)/', $responseHeaders, $arr)? 
> $arr[1]: 60;
>
>         if ($httpCode == 400) {
>
>             echo " the query Parameters are incorrect or the limit of 
> reports in the queue has been reached<br>";
>            echo " RequestId: {$requestId}<br>";
>            echo " JSON request code:<br>{$body}<br>";
>            echo " server response JSON:<br>{$responseBody}<br>";
>
>             break;
>
>         } elseif ($httpCode == 200) {
>
>             echo " Report created successfully<br>";
>            echo " RequestId: {$requestId}<br>";
>            echo $responseBody;
>
>             break;
>
>         } elseif ($httpCode == 201) {
>
>             echo "the Report was successfully queued in offline mode<br>";
>            echo " resend request after {$retryIn} seconds<br>";
>            echo " RequestId: {$requestId}<br>";
>
>             sleep($retryIn);
>
>         } elseif ($httpCode == 202) {
>
>             echo " the Report is generated offline.<br / >";
>            echo " resend request after {$retryIn} seconds<br>";
>            echo " RequestId: {$requestId}<br>";
>
>             sleep($retryIn);
>
>         } elseif ($httpCode == 500) {
>
>             echo " an error occurred while generating the report. Please 
> try again at < br>";
>            echo " RequestId: {$requestId}<br>";
>            echo " server response JSON:<br>{$responseBody}<br>";
>
>             break;
>
>         } elseif ($httpCode == 502) {
>
>             echo " report generation time exceeded server limit.<br / >";
>            echo " Please try to change the query parameters-reduce the 
> period and amount of data requested.<br / >";
>            echo " RequestId: {$requestId}<br>";
>
>             break;
>
>         } else {
>
>             echo " an unexpected error Occurred.<br / >";
>            echo " RequestId: {$requestId}<br>";
>            echo " JSON request code:<br>{$body}<br>";
>            echo " server response JSON:<br>{$responseBody}<br>";
>
>             break;
>
>         }
>    }
> }
>
> curl_close($curl);
>
> echo $responseBody;
>
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/14273f67-f276-4795-b1f3-aaefd35d5e1c%40googlegroups.com.
  • P... 'Василий Рогачев' via AdWords API and Google Ads API Forum
    • ... 'Василий Рогачев' via AdWords API and Google Ads API Forum
    • ... Василий Рогачев
    • ... Google Ads API Forum Advisor Prod
      • ... Василий Рогачев
    • ... Google Ads API Forum Advisor Prod

Reply via email to