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

ios - 如何在 iOS 中使用 Twitter/Social 框架获得关注者和关注者

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

如何从用户的 Twitter 帐户中获得所有关注者关注者

我获得关注者和关注人数。但是我需要关注者和关注用户的用户名。

这是我的代码。

- (void) getAccountInfo
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
        if (granted) {

            NSArray *accounts = [accountStore accountsWithAccountType:accountType];

            // Check if the users has setup at least one Twitter account

            if (accounts.count > 0)
            {
                ACAccount *twitterAccount = [accounts objectAtIndex:0];

                // Creating a request to get the info about a user on Twitter

                SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString"https://api.twitter.com/1.1/users/show.json"] parameters:[NSDictionary dictionaryWithObject:twitterAccount.username forKey"screen_name"]];
                [twitterInfoRequest setAccount:twitterAccount];

                // Making the request

                [twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    dispatch_async(dispatch_get_main_queue(), ^{

                        // Check if we reached the reate limit

                        if ([urlResponse statusCode] == 429) {
                            NSLog(@"Rate limit reached");
                            return;
                        }

                        // Check if there was an error

                        if (error) {
                            NSLog(@"Error: %@", error.localizedDescription);
                            return;
                        }

                        // Check if there is some response data

                        if (responseData) {

                            NSError *error = nil;
                            NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];


                            // Filter the preferred data

                            NSString *screen_name = [(NSDictionary *)TWData objectForKey"screen_name"];
                            NSString *name = [(NSDictionary *)TWData objectForKey"name"];

                            int followers = [[(NSDictionary *)TWData objectForKey"followers_count"] integerValue];
                            int following = [[(NSDictionary *)TWData objectForKey"friends_count"] integerValue];


                        }
                    });
                }];
            }
        } else {
            NSLog(@"No access granted");
        }
    }];

}



Best Answer-推荐答案


获取关注者列表

要获取关注者列表,请将您请求的 URL 更改为:

https://api.twitter.com/1.1/followers/list.json

它为跟随指定用户的用户返回用户对象的游标集合。

获取关注用户列表

要获取您关注的用户列表,请将您请求的 URL 更改为:

https://api.twitter.com/1.1/friends/list.json

它为指定用户关注的每个用户(也称为他们的“ friend ”)返回用户对象的游标集合。

我使用您的代码对其进行了测试,并且可以正常工作。基于 REST API v1.1 Resources

关于ios - 如何在 iOS 中使用 Twitter/Social 框架获得关注者和关注者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23409101/

回复

使用道具 举报

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

本版积分规则

关注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