Issue
I'm trying to get my establishments reviews from Google on my website. I think I figured out how to call the API, because after lots of trying I don't get autentifications errors anymore. But the return in the dump is just a "false" bool.
Does anyone knows what I'm doing wrong ?
<?php
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "00925334976-bgoe7tarvjisj9s6do9lgafmp4se7n99.apps.googleusercontent.com:OCSPX-WTrT5wshXVKInEUgWoab71uiaduY");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
var_dump(CallAPI('GET','https://mybusiness.googleapis.com/v4/accounts/00925334976-bgoe7tarvjisj9s6do9lgafmp4se7n99.apps.googleusercontent.com/locations/ChIJq2WiArxx5kcRWeHeXpoao90/reviews&key=OCSPX-WTrT5wshXVKInEUgWoab71uiaduY
'))
?>
(I deleted some chars from my API keys here, so to not share them openly here ^^")
Solution
Turns out it was just me not registering a credit card on the Google API interface, because they charge you for API calls of this nature outside of a certain quota. Which is to remain my best guess because I don't have permission from accountings to register valid payment informations for this, so I can't try, but it's pretty clear in the doc once you found the why of it.
Professor Abronsius comment was also correct, I was missing required options in my request and a valid certificate.
Answered By - Effcue Answer Checked By - Pedro (WPSolving Volunteer)