Google API dailyLimitExceededUnreg



我在PHP应用程序中使用Google URL缩短器API。它已经工作了几个月,但现在我收到此错误:

[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.

正在使用开发人员控制台中的服务器密钥,我重新生成了密钥,甚至删除了服务器访问密钥部分并重新添加它,但我不断收到相同的身份验证错误。

$query_array = json_encode( array( "longUrl" => $data['long_url'], 'key' => 'AIza-Key' ) ); 
$curl = curl_init( 'https://www.googleapis.com/urlshortener/v1/url' );
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query( $query_array ) ) ;             
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$short_url = json_decode( curl_exec( $curl ) );
$header = curl_getinfo($curl, CURLINFO_HEADER_OUT );
curl_close( $curl );
print_r( $short_url ) ; // shows above error

这个 API 应该没那么难,只需在 URL 字符串中添加服务器密钥,但我没有看到问题。有什么想法吗?

您要将key添加到 POST 正文,而不是作为 URL 查询字符串。将代码更改为以下内容:

$query_array = json_encode( array( "longUrl" => $data['long_url'] ) ); 
$curl = curl_init( 'https://www.googleapis.com/urlshortener/v1/url?key=AIza-Key' );

相关内容

  • 没有找到相关文章

最新更新