• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 15:08:31 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试将 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 限制...



Best Answer-推荐答案


运行 users/lookup 调用

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

您可以用逗号分隔 I.D 以调用一个电话。

响应示例请看这里:

https://snap.apigee.com/NHcXs4

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap