php - Goo.gl URL 缩短器停止工作 (php/curl)

标签 php curl goo.gl

出于某种原因,我的脚本今天停止工作。当我查看 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.
        )

)

最佳答案

我的以下回答不再有效。 Google 现在让您使用 Firebase 进行 URL 缩短。易于设置。

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


原来显示在多个网站中的这个旧功能现在也需要在 URL 部分中显示 api key ,以便谷歌将请求注册到您的帐户。

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

关于php - Goo.gl URL 缩短器停止工作 (php/curl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29214063/

相关文章:

javascript - 使用 XMLHttpRequest 通过 Google 的 Shortener api 缩短 url

php - 用我的应用程序打包一个 php 自包含可执行文件

php - Laravel 无法删除或更新父行 : a foreign key constraint fails

PHP:Curl 无法抓取我自己网站上的纯文本页面

curl - Golang 单足/双足oauth 1.0a认证

ruby - 如何使用 Net::Http 为 Goo.gl 缩短服务设置 header ?

PHP HTML 形式多维数组 MySQL

javascript - 如何在表单中发布 Quill 编辑器的内容?

php - PayPal IPN 监听器 - SSL 证书握手失败

firebase-dynamic-links - 如何为 Firebase 项目配置动态链接?