M.Sofien
M.Sofien

Reputation: 13

problem with urlshortener api when using file_get_contents()

I created his code, but it seems to work only on google.com links the problem when I change the parameter to another link, file_get_contents return 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');

Upvotes: 0

Views: 166

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117321

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

Upvotes: 1

Related Questions