开发者

Do you know a bit.ly API Php Script example? [closed]

开发者 https://www.devze.com 2022-12-31 07:39 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. 开发者_开发百科

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 8 years ago.

Improve this question

Do you have a php script that use the API from bit.ly ?


Going from Ceejayoz's Example, you can make it a one liner!

$short_url = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=bitlyusername&apiKey=bitlyapikey&longUrl=".urlencode("http://example.com")."&format=json"))->data->url;


I just googled your question : Example code

/* Example code */  
$link = "http://www.stackoverflow.com";  

print getSmallLink($link);  

function getSmallLink($longurl){  
// Bit.ly  
$url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longurl&login=YOURLOGIN&apiKey=YOURAPIKEY&format=json&history=1";  

$s = curl_init();  
curl_setopt($s,CURLOPT_URL, $url);  
curl_setopt($s,CURLOPT_HEADER,false);  
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);  
$result = curl_exec($s);  
curl_close( $s );  

$obj = json_decode($result, true);  
return $obj["results"]["$longurl"]["shortUrl"];  
}  


It's a very simple API.

$long_url = urlencode('http://example.com/');

$bitly_login = 'username';
$bitly_apikey = 'YOUR API KEY';

$bitly_response = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login={$bitly_login}&apiKey={$bitly_apikey}&longUrl={$long_url}&format=json"));

$short_url = $bitly_response->data->url;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号