How to get redirecting url link with php from bit.ly

前端 未结 4 1902
难免孤独
难免孤独 2020-12-21 05:11

I\'m trying to get url links to those bit.ly redirects. I\'ve tried to open bit.ly links with file_get_contents but it already gets content from redirected site

4条回答
  •  不知归路
    2020-12-21 05:26

    You can query bit.ly's API (documentation) for the long URL. You will need your username and API key (which can be found on your account page).

    $endpoint = 'http://api.bit.ly/v3/expand?';
    $params   = array(
        'shortUrl' => 'http://bit.ly/aUmUDq',
        'login'    => 'your_bitly_username',
        'apiKey'   => 'your_api_key',
        'format'   => 'txt'
    );
    $api_url = $endpoint . http_build_query($params);
    echo file_get_contents($api_url);
    

提交回复
热议问题