使用OAuth在CodeIgniter中基于Twitter ID检索Twitter数据

时间:2013-09-24 18:51:07

标签: php twitter twitter-oauth

我正在使用脚本来获取特定Twitter用户ID的数据。 Twitter用户ID为1897279429

我想展示它的名字和图像。我使用Twitter库有以下脚本。

        $this->load->config('twitter');
        require_once APPPATH.'libraries/TwitterAPIExchange.php';
        $settings = array(
            'oauth_access_token' => $this->config->item('access_token'),
            'oauth_access_token_secret' => $this->config->item('access_token_secret'),
            'consumer_key' => $this->config->item('consumer_key'),
            'consumer_secret' => $this->config->item('consumer_secret')
        );


        /** Perform a GET request and echo the response **/
        /** Note: Set the GET field BEFORE calling buildOauth(); **/
        $url = 'https://api.twitter.com/1.1/followers/ids.json';
        $getfield = '?username=SaswatRoutroy';
        $requestMethod = 'GET';
        $twitter = new TwitterAPIExchange($settings);
        echo $twitter->setGetfield($getfield)
                    ->buildOauth($url, $requestMethod)
                    ->performRequest();

问题是我想要显示个人资料图片的名称和网址,但我得到以下内容:

{"ids":[],"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0"}

现在可能是因为我没有任何关注者,并且网址错误。但我想要适当的方式和URL。

1 个答案:

答案 0 :(得分:1)

不仅仅是你。我只是将该用户ID放入Twython脚本中,我必须查找它们并得到它:

bash-3.2$ ./id-show.py 
User to show: 1897279429
Traceback (most recent call last):
  File "./id-show.py", line 14, in <module>
    data = twitter.show_user(user_id=target)
  File "build/bdist.macosx-10.3-fat/egg/twython/endpoints.py", line 426, in show_user
  File "build/bdist.macosx-10.3-fat/egg/twython/api.py", line 230, in get
  File "build/bdist.macosx-10.3-fat/egg/twython/api.py", line 224, in request
  File "build/bdist.macosx-10.3-fat/egg/twython/api.py", line 194, in _request
twython.exceptions.TwythonError: Twitter API returned a 403 (Forbidden), User has been suspended.
bash-3.2$ 

所以你拥有它,无论是谁被暂停。