从php获取Twitter粉丝

时间:2016-03-20 07:39:41

标签: php twitter

我如何从TwitterOAuth ??

获得推特粉丝
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

$content = $connection->get("statuses/user_timeline");
$_SESSION['a'] = $content;

echo '<pre>'.print_r($_SESSION['a'], true).'</pre>';

结果

Array
(
    [0] => stdClass Object
        (
            [created_at] => Sun Mar 20 04:42:17 +0000 2016
            [id] => 7.1141252133736E+17
            [id_str] => 711412521337356290
            [text] => yes
            [truncated] => 
            [source] => TipTopMusicClub1
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 404504657
                    [id_str] => 404504657
                    [name] => Ch Hong
                    [screen_name] => Ch_HonG8
                    [location] => George Town, Pinang
                    [description] => 21-08-1994
                    [url] => 
                    [entities] => stdClass Object
                        (
                            [description] => stdClass Object
                                (
                                    [urls] => Array
                                        (
                                        )

                                )

                        )

                    [protected] => 
                    [followers_count] => 7
                    [friends_count] => 28
                    [listed_count] => 0
                    [created_at] => Fri Nov 04 01:00:52 +0000 2011
                    [favourites_count] => 1
                    [utc_offset] => 28800
                    [time_zone] => Beijing
                    [geo_enabled] => 1
                    [verified] => 
                    [statuses_count] => 3
                    [lang] => en
                    [contributors_enabled] => 
                    [is_translator] => 
                    [is_translation_enabled] => 
                    [profile_background_color] => C0DEED
                    [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_tile] => 
                    [profile_image_url] => http://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_image_url_https] => https://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_link_color] => 0084B4
                    [profile_sidebar_border_color] => C0DEED
                    [profile_sidebar_fill_color] => DDEEF6
                    [profile_text_color] => 333333
                    [profile_use_background_image] => 1
                    [has_extended_profile] => 
                    [default_profile] => 1
                    [default_profile_image] => 
                    [following] => 
                    [follow_request_sent] => 
                    [notifications] => 
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [is_quote_status] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => und
        )

    [1] => stdClass Object
        (
            [created_at] => Wed Mar 16 03:19:49 +0000 2016
            [id] => 7.0994221947451E+17
            [id_str] => 709942219474505728
            [text] => Testing1
            [truncated] => 
            [source] => Twitter Web Client
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 404504657
                    [id_str] => 404504657
                    [name] => Ch Hong
                    [screen_name] => Ch_HonG8
                    [location] => George Town, Pinang
                    [description] => 21-08-1994
                    [url] => 
                    [entities] => stdClass Object
                        (
                            [description] => stdClass Object
                                (
                                    [urls] => Array
                                        (
                                        )

                                )

                        )

                    [protected] => 
                    [followers_count] => 7
                    [friends_count] => 28
                    [listed_count] => 0
                    [created_at] => Fri Nov 04 01:00:52 +0000 2011
                    [favourites_count] => 1
                    [utc_offset] => 28800
                    [time_zone] => Beijing
                    [geo_enabled] => 1
                    [verified] => 
                    [statuses_count] => 3
                    [lang] => en
                    [contributors_enabled] => 
                    [is_translator] => 
                    [is_translation_enabled] => 
                    [profile_background_color] => C0DEED
                    [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_tile] => 
                    [profile_image_url] => http://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_image_url_https] => https://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_link_color] => 0084B4
                    [profile_sidebar_border_color] => C0DEED
                    [profile_sidebar_fill_color] => DDEEF6
                    [profile_text_color] => 333333
                    [profile_use_background_image] => 1
                    [has_extended_profile] => 
                    [default_profile] => 1
                    [default_profile_image] => 
                    [following] => 
                    [follow_request_sent] => 
                    [notifications] => 
                )

            [geo] => 
            [coordinates] => 
            [place] => stdClass Object
                (
                    [id] => 527178fc119d340f
                    [url] => https://api.twitter.com/1.1/geo/id/527178fc119d340f.json
                    [place_type] => city
                    [name] => George Town
                    [full_name] => George Town, Pinang
                    [country_code] => MY
                    [country] => Malaysia
                    [contained_within] => Array
                        (
                        )

                    [bounding_box] => stdClass Object
                        (
                            [type] => Polygon
                            [coordinates] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 100.283305
                                                    [1] => 5.3525772
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 100.345993
                                                    [1] => 5.3525772
                                                )

                                            [2] => Array
                                                (
                                                    [0] => 100.345993
                                                    [1] => 5.4417467
                                                )

                                            [3] => Array
                                                (
                                                    [0] => 100.283305
                                                    [1] => 5.4417467
                                                )

                                        )

                                )

                        )

                    [attributes] => stdClass Object
                        (
                        )

                )

            [contributors] => 
            [is_quote_status] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                        )

                    [symbols] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => en
        )

    [2] => stdClass Object
        (
            [created_at] => Sun Jul 13 21:13:29 +0000 2014
            [id] => 4.8843104289465E+17
            [id_str] => 488431042894647296
            [text] => I’m supporting #Germany in the FIFA Global Stadium #GERARG
            [truncated] => 
            [source] => iOS
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 404504657
                    [id_str] => 404504657
                    [name] => Ch Hong
                    [screen_name] => Ch_HonG8
                    [location] => George Town, Pinang
                    [description] => 21-08-1994
                    [url] => 
                    [entities] => stdClass Object
                        (
                            [description] => stdClass Object
                                (
                                    [urls] => Array
                                        (
                                        )

                                )

                        )

                    [protected] => 
                    [followers_count] => 7
                    [friends_count] => 28
                    [listed_count] => 0
                    [created_at] => Fri Nov 04 01:00:52 +0000 2011
                    [favourites_count] => 1
                    [utc_offset] => 28800
                    [time_zone] => Beijing
                    [geo_enabled] => 1
                    [verified] => 
                    [statuses_count] => 3
                    [lang] => en
                    [contributors_enabled] => 
                    [is_translator] => 
                    [is_translation_enabled] => 
                    [profile_background_color] => C0DEED
                    [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png
                    [profile_background_tile] => 
                    [profile_image_url] => http://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_image_url_https] => https://pbs.twimg.com/profile_images/1757080140/PfejQ11E_normal
                    [profile_link_color] => 0084B4
                    [profile_sidebar_border_color] => C0DEED
                    [profile_sidebar_fill_color] => DDEEF6
                    [profile_text_color] => 333333
                    [profile_use_background_image] => 1
                    [has_extended_profile] => 
                    [default_profile] => 1
                    [default_profile_image] => 
                    [following] => 
                    [follow_request_sent] => 
                    [notifications] => 
                )

            [geo] => 
            [coordinates] => 
            [place] => 
            [contributors] => 
            [is_quote_status] => 
            [retweet_count] => 0
            [favorite_count] => 0
            [entities] => stdClass Object
                (
                    [hashtags] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [text] => Germany
                                    [indices] => Array
                                        (
                                            [0] => 15
                                            [1] => 23
                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [text] => GERARG
                                    [indices] => Array
                                        (
                                            [0] => 51
                                            [1] => 58
                                        )

                                )

                        )

                    [symbols] => Array
                        (
                        )

                    [user_mentions] => Array
                        (
                        )

                    [urls] => Array
                        (
                        )

                )

            [favorited] => 
            [retweeted] => 
            [lang] => en
        )

)

1 个答案:

答案 0 :(得分:0)

应该是:

$followers = $connection->get("followers/list");

我想你正在使用它:https://twitteroauth.com/

因此,您可以使用此处描述的方法:https://dev.twitter.com/rest/public