I want to be able to use the Twitter API for ios 5 to get all of the user followers and following user name into a NSDictionary
...
I've hit a road block though. I don't know how to use the Twitter API the do this... But my main problem is getting the user's username in the first place. How can I make an API request to find this users followers when I don't even know the users username?
Can someone give me an example on getting your Twitter users followers and following?
PS: I've already added the Twitter framework, and imported
Use FHSTwitterEngine
#import "FHSTwitterEngine.h"
Add SystemConfiguration.framework
Write following code to your viewDidLoad(for oauth login)
It's a combination of Apple's Twitter API and Twitter's own API. It's fairly straight forward once you read the code. I'm going to provide sample code for how to get the 'friends' for a Twitter account (this is the term for people that a user follows), which should be enough to get you going on a method to obtain the followers for an account.
First, add the
Accounts
andTwitter
frameworks.Now, let's get the Twitter account(s) present on a user's device.
Now we can get the friends for an account using the GET friends/ids command:
When you want the followers for an account, it's almost the same... Simple use the URL
http://api.twitter.com/1/followers/ids.format
and pass in the needed parameters as found via GET followers/idsHope this gives you a good head start.
UPDATE:
As pointed out in the comments, you should be using the updated API call:
https://api.twitter.com/1.1/followers/list.json
Referring to comments on post of runmad the source of error for "[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array" is that you have not setup twitter account in simulator. You need to sign twitter with your username and a temporary password provided by twitter.
Other source of error is "setObject for key error, key id is nil". To overcome that type below code : -
import
import
Note:- TWRequest has being deprecated. So instead you can also use this snippet: