Hitnirankari / bitly-api

Automatically exported from code.google.com/p/bitly-api
0 stars 0 forks source link

urlencode $url before shorten gets INVALID URI #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem (provide an exact http api call where
appropriate)?

/* returns the shortened url */
private function get_bitly_short_url($url,$login,$appkey,$format='txt') {
    $connectURL = 'http://api.bit.ly/v3/shorten?login='.$login.'&apiKey='.$appkey.'&uri='.urlencode($url).'&format='.$format;
    return self::curl_get_result($connectURL);
    }

/* returns a result form url */
private function curl_get_result($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$url = urlencode($url); // if I take the urlencode out, it works
$url = self::get_bitly_short_url($url,'myuser','myapikey');

I use the same url to test urlencode as in 
http://code.google.com/p/bitly-api/wiki/ApiBestPractices

What is the expected output? What do you see instead?
I expect to see shorten uri. Instead, I got the INVALID URI

What version of the product are you using? On what operating system?
I am using v3 bit.ly API on PHP 5.2.10 , Linux 2.6.18

Please provide any additional information below.
I double the encoded url. It is as it should be

http://betaworks.com/page?parameter=value#anchor

http%3A%2F%2Fbetaworks.com%2Fpage%3Fparameter%3Dvalue%23anchor

Please note that I use txt format, not a json format.

Original issue reported on code.google.com by duynguye...@gmail.com on 1 Dec 2011 at 6:29

GoogleCodeExporter commented 8 years ago
your function `get_bitly_short_url` already has `urlencode($url)` in it, so it 
is an error to do that twice.

Original comment by jeh...@bit.ly on 1 Dec 2011 at 8:27

GoogleCodeExporter commented 8 years ago
thanks for pointing that out :P

Original comment by duynguye...@gmail.com on 1 Dec 2011 at 8:34