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

I am using a script to fetch data of a particular Twitter user id. The twitter user id is 1897279429.

I want to show its name and image. I have the following script using the Twitter library.

        $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();

The issue is that I want the name and the URL of the profile picture to be displayed, but instead I get the following:

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

Now it may be because I don't have any follower, and the URL is wrong. But I want the appropriate way and URL.

dsdfd2322
dsdfd2322 它似乎在当时被暂停,因为这是Ben尝试的Twitter手柄。他的堆栈跟踪错误非常清楚。
2 年多之前 回复
dongwei1895
dongwei1895 TwitterID属于我,并未暂停。
2 年多之前 回复
duanmianhong4893
duanmianhong4893 以下答案似乎可以解决您遇到的问题,Saswat。虽然这里没有严格要求接受答案,但这样做肯定是礼貌的。你现在会这样做吗?
2 年多之前 回复
douxiduan8344
douxiduan8344 你经常抓Twitter吗?就像最少每天发送数百个请求一样。
接近 5 年之前 回复

1个回答

It's not just you. I just put that user ID into a Twython script I have to look them up and got this:

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$ 

So there you have it, whoever that was has been suspended.

duanjigua5753
duanjigua5753 可能只是其他人注册了该用户名,因为该帐户已于2年前被暂停。 或者也许该帐户在那段时间没有被暂停。 取决于您是否检查了用户ID或用户名...没关系,我刚刚检查过,该帐户已取消暂停,这就是您没有看到相同错误的原因。
4 年多之前 回复
dou9022
dou9022 我自己尝试过,但我没有得到同样的错误
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐