How to use the Google business profile performance API?

130 Views Asked by At

I tried to access the Google business profile performance API, but no matter what I do the program keeps throwing a 404 error.

First I tried to enable the Google business profile performance API alone, but that kept throwing the same error. Then I enabled all the API-related Google Business but still encountered the same 404 (the requested page was not found) error.

I followed the following API document provided by Google to get the business metrics, but still, it kept throwing a 404 error. The URL for the doc is https://developers.google.com/my-business/reference/performance/rest

As per the documentation, it asked me to enter the location ID as a part of the request URL and I followed the following site to get the IDs https://support.google.com/business/thread/203422357/what-is-your-business-profile-id?hl=en#:~:text=When%20you're%20logged%20into,Hope%20this%20helps but still it kept throwing the 404 error.

I also tried to replace the IDs that I found from the previous step with the place ID which I got by searching for my business at https://developers.google.com/maps/documentation/places/web-service/place-id It still displayed no output and kept throwing a 404 error. Please let me know what I should do to get an output from this API.

I used PHP and curl (both Post and Get based requests) to request the API endpoint, the code snippet used is as follows.

    $curl = curl_init();
    curl_setopt_array($curl, [
    CURLOPT_URL => "https://businessprofileperformance.googleapis.com/v1/locations/LocationID:getDailyMetricsTimeSeries",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_POST=>true,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer ".json_encode($_SESSION['access_token']['access_token']),
      'Content-Length: 9999999',
      "Accept: application/json"
    ],
  ]);
    $response = curl_exec($curl);
    print_r($response);
    $resArr=json_decode($response,true);

------------ Alternative Code Used -----------

$curl = curl_init();
$headers = [
          "Authorization: Bearer ".json_encode($_SESSION['access_token']['access_token']),
          'Content-Length: 9999999',
          "Accept: application/json"
        ];
curl_setopt($curl, CURLOPT_URL, "https://businessprofileperformance.googleapis.com/v1/locations/LocationID:getDailyMetricsTimeSeries");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
print_r($response);
$resArr=json_decode($response,true);

I appreciate any help you can provide.

0

There are 0 best solutions below