gpt4 book ai didi

iphone - Twitter API(从 ID 到屏幕名称)

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:14:33 24 4
gpt4 key购买 nike

我正在尝试将 Twitter 用户 ID(例如:77687121)转换为他们的用户名或屏幕名称(两者都可以),但我遇到了一个问题...

我尝试按照这个 SO 问题的说明进行操作,但作为 Twitter api 的新手以及 Objective c 本身让我很难理解:http://stackoverflow.com/questions/10020672/php- twitter-api-get-users-lookup-grabbing-screen-name-from-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 限制...

最佳答案

运行users/lookup调用

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

你可以用逗号分隔ID来调用一个电话。

有关响应示例,请看这里:

https://snap.apigee.com/NHcXs4

关于iphone - Twitter API(从 ID 到屏幕名称),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11621677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com