开发者

Adding twitter followers to my DB

i am using a php script to automate posts to twitter. the script to post is woking, but i want it to pull a list of users from my followers automatically. at the moment i am having to import CSV files 开发者_C百科into my mysql database. i know there is a way that i could pull followers and dump them into the DB directly using twitters API, but I lack the skill necessary to code said function.


I would suggest that you request your followers from Twitter's API in JSON format, then use PHP's json_decode() function to get something usable from PHP from the results. It's much easier than trying to use XML. You only have to make sure you have the JSON extension installed for PHP:

<?php
$username = 'johndoe';
$ch = curl_init( 'http://api.twitter.com/1/statuses/followers/' . $username . '.json' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 ); // set curl timeout to 60 sec. you might want to increase this, as Twitter can be slow sometimes.
$followers = json_decode( curl_exec( $ch ) );
curl_close( $ch );

// now just go through $followers and do with the data what you will
?>


Do you mean this: Twitter Api statuses followers and this: simple xml php and I have a post on my blog here about saving an array to a mysql table that you can work with.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜