2016-10-27 3 views
2

Ich habe URL Kürzel Skript das funktionierte gut, bis ich Website-Referrer KEY Einschränkung in der API-Konsole hinzugefügt (was ich tun musste). Jetzt gebe ich keine kurze URL zurück. Ich erhalte folgende Fehlermeldung:Google URL Shortener - nicht angegeben HTTP Referer

Array ([error] => Array ([errors] => Array ([0] => Array ([domain] => usageLimits [reason] => ipRefererBlocked [message] => The request did not specify any referer. Please ensure that the client is sending referer or use the API Console to remove the referer restrictions. [extendedHelp] => https://console.developers.google.com/apis/credentials?project=XXXXXXXXX )) [code] => 403 [message] => The request did not specify any referer. Please ensure that the client is sending referer or use the API Console to remove the referer restrictions.))

Meine PHP:

<?php 

$longurl = "http://example.com"; 

$api_key_google = "XXXX_API_KEY_XXXXX"; 
$curl = curl_init('https://www.googleapis.com/urlshortener/v1/url?key='.$api_key_google); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($curl, CURLOPT_HEADER, 0); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type:application/json')); 
curl_setopt($curl, CURLOPT_POST, 1); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(array('longUrl' => $longurl))); 
$return = json_decode(curl_exec($curl), true); 
curl_close($curl); 

print_r($return);  
echo $shortDWName = $return['id']; 

?> 

Was soll ich hier fehlt? Danke im Vorraus für deine Hilfe.

Antwort

4

Versuchen Sie, fügen Sie diese Zeile

curl_setopt($curl, CURLOPT_HEADER, 0); 
// should add this line 
curl_setopt($ch, CURLOPT_REFERER, '[your restriction domain]'); 
+0

ja, das ist mein Problem gelöst, dank – Nita

Verwandte Themen