将twitter粉丝列表导出到csv文件

时间:2012-09-21 20:57:58

标签: php twitter

我使用以下php代码来获取用户的Twitter粉丝。我想将此数据导出到csv文件并添加过滤器以仅保存超过100个关注者的关注者。

<script src="http://code.jquery.com/jquery-latest.js"></script>

<?php
  $trends_url = "http://api.twitter.com/1/statuses/followers/pthiongo.json";
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL, $trends_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $curlout = curl_exec($ch);
  curl_close($ch);
  $response = json_decode($curlout, true);
  foreach($response as $friends){
  $thumb = $friends['profile_image_url'];
  $url = $friends['screen_name'];
  $name = $friends['name'];
  echo $friends['screen_name'];

 ?>
<a title="<?php echo $name;?>" href="http://www.twitter.com/<?php echo $url;?>"><img class="photo-img" src="<?    php echo $thumb?>" border="0" alt="" width="40" /></a>
<?php
 } 
?>

2 个答案:

答案 0 :(得分:1)

首先,http://blog.gabrieleromanato.com/2012/06/jquery-get-twitter-followers-count/

然后在PHP中使用if (followers_count > 99)来显示

答案 1 :(得分:0)

以编程方式,您可以使用下面的示例请求,使用Instagram API请求最多100位您自己的关注者列表。

以下示例请求来自SnippetLib:

https:api.instagram.comv1users3followed-by?access_token=ACCESS-TOKEN

此路线(来自nbyim.com)使用分页来绕过速率限制:

from instagram.client import InstagramAPI

user_id=''
access_token = ''
client_secret = ''

api = InstagramAPI(access_token=access_token, client_secret=client_secret)

followers = []

# Get the followers list
for p in api.user_followed_by(user_id=user_id, as_generator=True, max_pages=None):
followers.extend(p[0])

# Convert from an instagram.models.User list to a list of strings
followers = [str(u).replace('User: ', '') for u in followers]

print len(followers), 'followers'
print followers

要自动执行CSV过程,您可以使用像Crowdbabble这样的服务:https://www.crowdbabble.com/download-all-instagram-followers/