Shortened Goo.gl URL Shortening (php / curl)

For some reason, my script stops working today. When I look in the API control panel, I still have 100% of the use. Any ideas? Did they change the auth path?

function url_small($url) { //This is the URL you want to shorten $longUrl = $url; $apiKey = '#####HIDDEN######'; //Get API key from : http://code.google.com/apis/console/ $postData = array('longUrl' => $longUrl, 'key' => $apiKey); $jsonData = json_encode($postData); $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url'); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); curl_setopt($curlObj, CURLOPT_POST, 1); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData); $response = curl_exec($curlObj); //change the response json string to object $json = json_decode($response); curl_close($curlObj); return $json->id; } 

Answer

 stdClass Object ( [error] => stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [domain] => usageLimits [reason] => dailyLimitExceededUnreg [message] => Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup. [extendedHelp] => https://code.google.com/apis/console ) ) [code] => 403 [message] => Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup. ) ) 
+7
php curl
source share
1 answer

My answer below is not valid. Google now forces you to use Firebase to shorten URLs. Easy to set up.

https://firebase.google.com/docs/dynamic-links/rest


Thus, it turns out that this old feature, which appears on several websites, now requires that the API key also appear in the URL section in order for Google to register the request in your account.

 curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url'); 

switched to it

 curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey); 
+27
source share

All Articles