使用file_get_contents()时urlshortener api出现问题

时间:2018-09-19 11:02:58

标签: php google-api google-url-shortener

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

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

1 个答案:

答案 0 :(得分:1)

  

从2018年3月30日开始,我们将拒绝对goo.gl URL缩短器的支持。请参阅此博客文章以了解详细的时间表和替代方法。

您应该注意,Google URL Shortener API已被Transitioning Google URL Shortener to Firebase Dynamic Links停用

他们已经开始调整API中的许多功能。我怀疑您遇到的问题是由于这个原因。

您应该切换到FireBase Dynamic links