简体   繁体   中英

Can anybody help me with the twitter home_timeline api?

I have the following code

    $curl_handle = curl_init();
    $api_url = 'http://api.twitter.com/1/statuses/home_timeline.json';
        curl_setopt($curl_handle, CURLOPT_URL, $api_url);
    if (true) {
        curl_setopt($curl_handle, CURLOPT_USERPWD, 'mytwitterusername:mypass');
    }
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
    $twitter_data = curl_exec($curl_handle);
    $this->http_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
    $this->last_api_call = $api_url;
    curl_close($curl_handle);
    var_dump($this->http_status);
    var_dump($twitter_data);
    return $twitter_data;

And it returns {"errors":[{"code":53,"message":"Basic authentication is not supported"}]}

Can anyone figure it out what is the problem. Thanks in advance..

Exactly as it says. Twitter Basic auth, which is what you're doing, is no longer supported. You have to use OAuth instead. I recommend looking into this PHP library to easily work with Twitter via PHP:

https://github.com/abraham/twitteroauth

As the error message states, the problem is that basic authentication is not supported.

You need to use OAuth to authenticate with Twitter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM