2
我試圖將Twitter用戶ID(例如:77687121)變成他們的用戶名或屏幕名稱(任何一個都可以),但我遇到了一個問題.. 。Twitter API(從ID到屏幕名稱)
我嘗試了下面這個SO問題的指導,但是對於Twitter API以及Objective C本身也是一個新東西讓我很難理解:http://stackoverflow.com/questions/10020672/php- Twitter的API,讓用戶查對抓住屏幕名稱 - 從-ID
我從教程寫了下面的代碼,我得到這個...
- (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"]);
}];
}
此方法有時會給我一個錯誤,有時它會得到中斷,並顯示一些彙編代碼...下面是錯誤... 以及第一個NSLOG();在方法的開始......
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)
另外這是一個很好的方式,通過每一個人的Twitter ID去(即使我有成千上萬)只是爲了讓每個用戶的網名。我知道Twitter的API限制...
我得到的問題,當我把這個API – Jitendra 2014-04-09 07:14:45
它被更新爲1.1和落後驗證:/ https://api.twitter.com/ 1.1 /用戶/ lookup.json?user_id = 77687121,43662011,6253282 – Chamilyan 2014-04-10 08:26:20
可以請你看看這個http://stackoverflow.com/questions/22955296/twiiter-api-failed-to-get-followers-and-follow-細節 – Jitendra 2014-04-10 09:03:19