I Keep getting this error despite making many apps and also signing up for a free account. The objective was to create URL Shortener:
stdClass Object ( [error] => stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [domain] => usageLimits [reason] => userRateLimitExceededUnreg [message] => User Rate Limit Exceeded. Please sign up [extendedHelp] => https://code.google.com/apis/console ) ) [code] => 403 [message] => User Rate Limit Exceeded. Please sign up ) )
Following is the code:
$apiKey='......';
$url='http://www.example.com';
function httpsPost($postDatas)
{
$jsonData = json_encode($postDatas);
//echo $jsonData."<br><br>";
$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;
}
$postData = array('longUrl' => $url,'key' => $apiKey);
$info = httpsPost($postData);
print_r($info);
//die();
if($info->id)$shorturl=$info->id;else $shorturl="Unsuccessful";
echo "<br><br> Short URL: ".$shorturl;
I Keep getting this error despite making many apps and also signing up for a full account. The objective was to create URL Shortener:
403
The following solved the problem
https://www.googleapis.com/urlshortener/v1/url?key=.......