Goo.gl URL缩短程序已停止工作(php/ccurl)



由于某种原因,我的脚本今天停止工作。当我查看API控制面板时,我仍然有100%的剩余使用。有什么想法吗?他们改变身份验证方式了吗?

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;
    }

响应

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

我下面的答案不再有效。谷歌现在让你使用Firebase来缩短URL。易于设置。

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


因此,这个显示在多个网站上的旧功能现在也需要在URL部分显示api密钥,以便谷歌将请求注册到您的帐户。

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

切换到此

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

相关内容

  • 没有找到相关文章

最新更新