谷歌网址缩短-没有指定的HTTP参考


Google URL Shortener - not specified HTTP Referer

我有网址缩短脚本工作得很好,直到我在API控制台添加了网站参考键限制(我必须这样做)。现在我不返回短url。我得到以下错误:

Array ([error] => Array ([errors] => Array ([0] => Array ([domain])=> usageLimits [reason] => ipRefererBlocked [message] =>请求没有指定任何referer。请确保客户正在发送引用或使用API控制台来删除引用限制。[extendedHelp] =>https://console.developers.google.com/apis/credentials?project=XXXXXXXXX)) [code] => 403 [message] =>请求没有指定任何参数推荐人。请确保客户发送推荐人或使用API控制台,以删除引用限制。))

我的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'];
?>

我在这里错过了什么?提前感谢您的帮助

尝试添加这一行

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