Jump to content

using curl for bit.ly?


salman_ahad@yahoo.com

Recommended Posts

 

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

Link to comment
https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/
Share on other sites

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'}; 
    } 
?>

Link to comment
https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972524
Share on other sites

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'}; 
    } 
?>

 

Link to comment
https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972534
Share on other sites

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!
?>


Link to comment
https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972541
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.