获取关注者的姓名 - Twitter

Posted

技术标签:

【中文标题】获取关注者的姓名 - Twitter【英文标题】:Get name of followers - Twitter 【发布时间】:2013-08-12 15:12:44 【问题描述】:

我正在尝试从 twitter 帐户获取关注者列表。 我需要从这些朋友那里得到一份名单。

我正在尝试使用以下代码获取具有这些名称的数组:

NSArray *users = [twitterFriends objectForKey:@"name"];

但它崩溃了..

这是我的 json 响应。

(
    
    "contributors_enabled" = 0;
    "created_at" = "Thu Aug 12 20:43:32 +0000 2010";
    "default_profile" = 0;
    "default_profile_image" = 0;
    description = "Software House, Business Plan, Consultoria Empresarial, BPM, JJAERP";
    entities =         
        description =             
            urls =                 (
            );
        ;
        url =             
            urls =                 (
                                    
                    "display_url" = "jjaconsulting.com.br";
                    indices =                         (
                        0,
                        22
                    );
                    url = "http://t.co/9KuqGoNcTh";
                
            );
        ;
    ;
    "favourites_count" = 0;
    "follow_request_sent" = 0;
    "followers_count" = 46;
    following = 0;
    "friends_count" = 227;
    "geo_enabled" = 1;
    id = 177691414;
    "id_str" = 177691414;
    "is_translator" = 0;
    lang = pt;
    "listed_count" = 0;
    location = " Campinas/SP ";
    name = "JJA Consulting";
    notifications = 0;
    "profile_background_color" = 0099B9;
    "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/378800000039639419/aed884dcff4f8d9aad7c8ae74bc9a151.jpeg";
    "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/378800000039639419/aed884dcff4f8d9aad7c8ae74bc9a151.jpeg";
    "profile_background_tile" = 0;
    "profile_image_url" = "http://a0.twimg.com/profile_images/2759565559/f0da5bb0cf89e41c063758dd4a2266b2_normal.png";
    "profile_image_url_https" = "https://si0.twimg.com/profile_images/2759565559/f0da5bb0cf89e41c063758dd4a2266b2_normal.png";
    "profile_link_color" = 0099B9;
    "profile_sidebar_border_color" = FFFFFF;
    "profile_sidebar_fill_color" = 95E8EC;
    "profile_text_color" = 3C3940;
    "profile_use_background_image" = 1;
    protected = 0;
    "screen_name" = JJAConsulting;
    status =         
        contributors = "<null>";
        coordinates = "<null>";
        "created_at" = "Wed Aug 07 20:20:15 +0000 2013";
        entities =             
            hashtags =                 (
            );
            symbols =                 (
            );
            urls =                 (
                                    
                    "display_url" = "wp.me/p3yYQw-dX";
                    "expanded_url" = "http://wp.me/p3yYQw-dX";
                    indices =                         (
                        33,
                        55
                    );
                    url = "http://t.co/c0lw6XTXhr";
                
            );
            "user_mentions" =                 (
            );
        ;
        "favorite_count" = 0;
        favorited = 0;
        geo = "<null>";
        id = 365205769249357825;
        "id_str" = 365205769249357825;
        "in_reply_to_screen_name" = "<null>";
        "in_reply_to_status_id" = "<null>";
        "in_reply_to_status_id_str" = "<null>";
        "in_reply_to_user_id" = "<null>";
        "in_reply_to_user_id_str" = "<null>";
        lang = pt;
        place = "<null>";
        "possibly_sensitive" = 0;
        "retweet_count" = 0;
        retweeted = 0;
        source = "<a href=\"http://publicize.wp.com/\" rel=\"nofollow\">WordPress.com</a>";
        text = "JXML - Mensageria JJA Consulting http://t.co/c0lw6XTXhr";
        truncated = 0;
    ;
    "statuses_count" = 1731;
    "time_zone" = Brasilia;
    url = "http://t.co/9KuqGoNcTh";
    "utc_offset" = "-10800";
    verified = 0;
,
    
    "contributors_enabled" = 0;
    "created_at" = "Sun Aug 14 18:52:23 +0000 2011";
    "default_profile" = 1;
    "default_profile_image" = 0;
    description = "";
    entities =         
        description =             
            urls =                 (
            );
        ;
        url =             
            urls =                 (
                                    
                    "display_url" = "atacadaomicrotech.com.br";
                    "expanded_url" = "http://www.atacadaomicrotech.com.br/";
                    indices =                         (
                        0,
                        22
                    );
                    url = "http://t.co/wbPX342NF2";
                
            );
        ;
    ;
    "favourites_count" = 1;
    "follow_request_sent" = 0;
    "followers_count" = 13;
    following = 0;
    "friends_count" = 115;
    "geo_enabled" = 1;
    id = 355045961;
    "id_str" = 355045961;
    "is_translator" = 0;
    lang = pt;
    "listed_count" = 0;
    location = "Ribas do Rio Pardo - MS";
    name = "Microtech Info";
    notifications = 0;
    "profile_background_color" = C0DEED;
    "profile_background_image_url" = "http://a0.twimg.com/images/themes/theme1/bg.png";
    "profile_background_image_url_https" = "https://si0.twimg.com/images/themes/theme1/bg.png";
    "profile_background_tile" = 0;
    "profile_image_url" = "http://a0.twimg.com/profile_images/1495205945/microtech_normal.jpg";
    "profile_image_url_https" = "https://si0.twimg.com/profile_images/1495205945/microtech_normal.jpg";
    "profile_link_color" = 0084B4;
    "profile_sidebar_border_color" = C0DEED;
    "profile_sidebar_fill_color" = DDEEF6;
    "profile_text_color" = 333333;
    "profile_use_background_image" = 1;
    protected = 0;

【问题讨论】:

@"name" 键的对象是字符串,而不是数组。 你如何获得关注者的名字,我想要这个名字你能告诉我你的代码吗... 【参考方案1】:

假设twitterFriends是字典的根数组,你可以通过这样做得到名字列表:

NSArray *names = [twitterFriends valueForKeyPath:@"name"];

【讨论】:

以上是关于获取关注者的姓名 - Twitter的主要内容,如果未能解决你的问题,请参考以下文章

Instagram Graph API,获取关注者的关注者

Twitter API - 为拥有数百万关注者的帐户获取关注者列表的有效方法

获取WordPress中Twitter关注者的数量

在 discord.js 中更改关注者的昵称

excel用VLOOKUP函数怎么查找多个数据,要查最低工资者的姓名(3个)

用于取消关注 instagram 取消关注者的 cURL 代码