开发者

Twitter feed protected by default?

Attempting to write a script that'll fetch a couple users' latest tweets. Works great on my own twitter account, but not on the other accounts, which were created very recently (< 7 days).

Upon checking their account settings, they report that "Protect my tweets" is unchecked, which should mean that I can access them publicaly using the twitter API.

Relevant code:

$url = 'http://api.twitter.com/1/statuses/user_timeline.json?user_id=' . $twID . '&count=' . $count . '&trim_user=true';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return[] = json_decode(curl_exec($ch), true);

Result from Twitter API:

[0] => Array
    (
        [error] => This method requires authentication.
        [request] => /1/statuses/user_timeline.json?user_id=1540067663&count=6&trim_user=true
开发者_如何转开发    )

[1] => Array
    (
        [0] => Array
            (
                [favorited] => ... // Success -- Output truncated for brevity.
    )

[2] => Array
    (
        [error] => This method requires authentication.
        [request] => /1/statuses/user_timeline.json?user_id=1532872753&count=6&trim_user=true
    )

)

Are new accounts automatically protected in the Twitter API?


Where is $twID coming from?

I actually had the opposite where the screen name param giving me wonky results so I had to use the userid. You have to love the Twitter API sometimes.

You might find this call useful which gives you interchanging information between the two

http://api.twitter.com/1/users/lookup.xml?screen_name=twitterapi http://api.twitter.com/1/users/lookup.xml?user_id=6253282


Utilising screen_name instead of user_id resolved the issue to my satisfaction.

The final link format:

$url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $twID . '&count=' . $count;

Possibly this may be a reportable bug with the Twitter API... but we shall see. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜