Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用文件获取内容()时urlshortener api出现问题_Php_Google Api_Google Url Shortener - Fatal编程技术网

Php 使用文件获取内容()时urlshortener api出现问题

Php 使用文件获取内容()时urlshortener api出现问题,php,google-api,google-url-shortener,Php,Google Api,Google Url Shortener,我创建了他的代码,但它似乎只在google.com链接上工作。当我将参数更改为另一个链接时,file_get_contents返回false function google_url_short($link) { $data = array('longUrl' => $link); $context = [ 'http' => [ 'method' => 'post', 'header' =>

我创建了他的代码,但它似乎只在google.com链接上工作。当我将参数更改为另一个链接时,file_get_contents返回false

function google_url_short($link)
{
    $data = array('longUrl' => $link);
    $context = [
        'http' => [
            'method' => 'post',
            'header' => 'Content-Type:application/json',
            'content' => '{"longUrl":"'.$link.'"}'
        ]
    ];
    $context = stream_context_create($context);
    $result = file_get_contents('https://content.googleapis.com/urlshortener/v1/url?alt=json&key=AIzaSyDqOQwOBE0gH0_yQuqVJlPFgvSdbgyppE', false, $context);
}
google_url_short('https://www.google.com');
从2018年3月30日开始,我们将拒绝对goo.gl URL shortener的支持。有关详细的时间表和备选方案,请参阅本博客文章

您应该知道Google URL Shortener API已经停止使用

他们已经开始调整API中的一些特性。我怀疑你的问题就是因为这个


您应该切换到

您可能希望从该代码中删除密钥。示例密钥是否不真实;)