首页 > 解决方案 > 使用 file_get_contents() 时 urlshortener api 的问题

问题描述

我创建了他的代码,但是当我将参数更改为另一个链接时,它似乎只适用于 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');

标签: phpgoogle-apigoogle-url-shortener

解决方案


Starting March 30, 2018, we will be turning down support for goo.gl URL shortener. Please see this blog post for detailed timelines and alternatives.

You should be aware that the Google URL Shortener API has been discontinued Transitioning Google URL Shortener to Firebase Dynamic Links

They have already begun tuning down a number of the features within the API. I suspect the issue you are having is due to that.

You should switch to FireBase Dynamic links


推荐阅读