Twitter API (From ID to Screen Name)-Collection of common programming errors

I’m trying to turn a Twitter user id (Ex: 77687121) into their username or screen name (either one will work), but I’ve ran into a problem…

I tried following directions to this SO question, but being new to the Twitter api as well as Objective c itself made it hard for me to understand: http://stackoverflow.com/questions/10020672/php-twitter-api-get-users-lookup-grabbing-screen-name-from-id

I wrote the following code from that tutorial and I got this…

- (void) turnFriendId: (NSString *)friID {
// Setup the URL, as you can see it's just Twitter's own API url scheme. In this case we want to receive it in JSON
NSLog(@"%@",friID);
NSURL *followingURL = [NSURL URLWithString:@"https://api.twitter.com/1/users/show.json"];
// Pass in the parameters (basically '.ids.json?screen_name=[screen_name]')
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:friID, @"id_str", nil];
// Setup the request
TWRequest *twitterRequest = [[TWRequest alloc] initWithURL:followingURL
                                                parameters:parameters
                                             requestMethod:TWRequestMethodGET];
// This is important! Set the account for the request so we can do an authenticated request. Without this you cannot get the followers for private accounts and Twitter may also return an error if you're doing too many requests
[twitterRequest setAccount:theAccount];
// Perform the request for Twitter friends
[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    if (error) {
        // deal with any errors - keep in mind, though you may receive a valid response that contains an error, so you may want to look at the response and ensure no 'error:' key is present in the dictionary
    }
    NSError *jsonError = nil;
    // Convert the response into a dictionary
    NSDictionary *twitterGrabbedUserInfo = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONWritingPrettyPrinted error:&jsonError];
    // Grab the Ids that Twitter returned and add them to the dictionary we created earlier
    NSLog(@"%@", [twitterGrabbedUserInfo objectForKey:@"name"]);
}];
}

This method will sometimes give me an error and sometimes it will get break and show me some assembly code… Below is the error… As well as the first NSLOG(); at the beginning of the method…

2012-07-23 18:42:05.786 VideoPush[17625:3503] 1882208
2012-07-23 18:42:17.692 VideoPush[17625:3503] -[__NSCFType credentialForAccount:]: unrecognized selector sent to instance 0x1afeb0
2012-07-23 18:42:17.694 VideoPush[17625:3503] -[__NSCFType enabledDataclassesForAccount:]: unrecognized selector sent to instance 0x1afeb0
2012-07-23 18:42:17.696 VideoPush[17625:3503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType enabledDataclassesForAccount:]: unrecognized selector sent to instance 0x1afeb0'
*** First throw call stack:
(0x355e188f 0x37988259 0x355e4a9b 0x355e3915 0x3553e650 0x3055bfc3 0x3055b98b 0x35065d2f 0x355c1975 0x3553c1df 0x3554fb5f 0x35080b8b 0x35080b2b 0x3257dfdf 0x3257e88d 0x3257ea6b 0x3257eea5 0x355e3a83 0x3553e650 0x3055cf85 0x322047b1 0x32204e5d 0x31f1f 0x31d8d 0x32204f8b 0x3446ec59 0x34470d0f 0x34470b75 0x344717e7 0x3299edfb 0x3299ecd0)
terminate called throwing an exception(lldb)

Also is this a good way to go through each individual Twitter id (even if I have thousands) just to get the screen name of each user. I know Twitter has API limits…

  1. Run the users/lookup call

    http://api.twitter.com/1/users/lookup.json?user_id=77687121,43662011,6253282
    

    you can separate the I.D’s by comma to make one call.

    For a response example look here:

    https://snap.apigee.com/NHcXs4

Originally posted 2013-11-16 20:53:31.