我正在尝试使一个批量bit.ly更短,它从txt文件中读取链接列表并输出缩短的链接
问题是我不知道该怎么做,而且如果你做链接太快,bit.ly会有一个api限制。我发现如果你每秒做5个链接,它应该会起作用。
如何一次缩短1200个链接?
<?php
$sites = array(
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link2.com',
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link1.com',
);
foreach ( $sites as $site ) {
$shortened_url = file_get_contents($site);
if($shortened_url)
echo "$shortened_url <br/>";
}
die();
?>发布于 2012-09-24 02:13:03
在5个链路休眠5秒(或sleep()声明的秒数)后使用API:
<?php
$sites = array(
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link2.com',
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link1.com',
);
$i = 0;
foreach ( $sites as $site ) {
$shortened_url = file_get_contents($site);
if($shortened_url) {
echo "$shortened_url <br/>";
}
$i++;
if($i%5 == 0){
sleep(5);
}
}
die();
?>https://stackoverflow.com/questions/12554863
复制相似问题