?
Solved

How do you get the followers number of followers in Twitter using twitteroauth?

Posted on 2011-09-16
8
Medium Priority
?
439 Views
Last Modified: 2013-12-13
Hi,

I am using abraham's twitteroauth library to integrate my application with Twitter. I have successfully managed to complete authentication and post tweets. Now I am trying to pull out some user statistics like number of followers, following, tweets, retweets, etc.

But I cannot see any direct method to pull out our followers number of followers. Say if person A follows me, then I am interested in knowing the number of followers person A has.

Does any one has any idea on how to do this. Any help would be appreciated.

Thanks in advance.
0
Comment
Question by:ishani_v
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:h4hardy
ID: 36553145
Hi ishani,

you can try with the below code,

<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() – 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?> 

Open in new window

0
 
LVL 4

Expert Comment

by:h4hardy
ID: 36553150
Hi,

you can also try with this..

See this: http://api.twitter.com/1/users/show.json?screen_name=

It returns a json object which you can use to get the followers count.

Here, the count is stored in ‘followers_count’
0
 
LVL 29

Expert Comment

by:fibo
ID: 36553880
(just en passant)
If your program does not work under IE9, check with FF. There was once a problem with IE9 where twitter API returned a json object that IE did not andle correctly. This problem has been solved... but maybe not for the complete API
See http://www.experts-exchange.com/Q_27277495.html
0
 

Author Comment

by:ishani_v
ID: 36559106
@h4hardy

Thanks for your reply. But your code doesn't seem to be working. I would like to make myself clear again that I already have the code to get count of followers for a  particular user. What I want is that I want to see the no of followers for the people who I am following.

Can that be done? I have attached my code that displays to me my number of followers. I want a count that shows the no of followers for any of the people I'm following.

Thanks.
$credentials = $oauth->get("account/verify_credentials");
$content = $oauth->get('statuses/user_timeline');

foreach ($content as $item) 
{     // ---- start foreach ---- 

 	
	//No of Followers
	$followers = $item->user->followers_count;
}

echo "<br>Followers: <strong>". $followers ."</strong> \r\n";

Open in new window

0
 
LVL 30

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 36897098
statuses/user_timeline gives you statuses, not users, if you want a list of your followers you need to use followers/ids, providing your user_id as a parameter, and then loop all users returned from the request, there is no single request doing what you want.

Bye, Olaf.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question