Php 使用文件获取内容()时urlshortener api出现问题
我创建了他的代码,但它似乎只在google.com链接上工作。当我将参数更改为另一个链接时,file_get_contents返回falsePhp 使用文件获取内容()时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' =>
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中的一些特性。我怀疑你的问题就是因为这个
您应该切换到您可能希望从该代码中删除密钥。示例密钥是否不真实;)