salman_ahad@yahoo.com Posted December 6, 2009 Share Posted December 6, 2009 I am trying to shorten my link using bit.ly API. If someone has idea of using curl and using this API, please let me know $host = "http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.ideatoceo.com"; var_dump($host); I am not properly calling the API or not using curl...please help Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/ Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 You don't need curl.. but you're not even pulling the data from it. $url = file_get_contents('http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.ideatoceo.com'); json_decode($url); //Or whatever API specifies.. Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972517 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 6, 2009 Author Share Posted December 6, 2009 I am getting "parse" error while using this code <?php $longurl = "http://advertise.ideatoceo.com"; public function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972524 Share on other sites More sharing options...
salathe Posted December 6, 2009 Share Posted December 6, 2009 The visibility keywords (public in your code) are only available within class definitions, not for functions. Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972526 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 6, 2009 Author Share Posted December 6, 2009 I removed public but there is no output. <?php $longurl = "http://advertise.ideatoceo.com"; function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972534 Share on other sites More sharing options...
salathe Posted December 6, 2009 Share Posted December 6, 2009 You're not calling the function. Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972538 Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 I removed public but there is no output. <?php $longurl = "http://advertise.ideatoceo.com"; function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } echo get_bitly_shorturl($longurl); //Done! ?> Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972541 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 6, 2009 Author Share Posted December 6, 2009 Thanks !! Quote Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.