Twitter v1.1: 400 Bad request

10,579

Solution 1

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi redirects me to https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi

Looks like 1.1 is the same thing as 1

UPD: Looks like this is a rate limit (as 1.1 link worked for me 2 hours ago). Even if you hit API page for the first time, some of your apps (descktop or mobile) could use API methods.

UPD2: in 1.1 400 Bad request means you are not autorized (https://dev.twitter.com/docs/error-codes-responses, https://dev.twitter.com/docs/auth/oauth#user-context). So you need to get user context

Solution 2

You need to authenticate and authorize using oauth before using v1.1 apis Here is something which works with python tweepy - gets statuses from users timeline

def twitter_fetch(screen_name = "BBCNews",maxnumtweets=10):
   'Fetch tweets from @BBCNews'
    # API described at https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

    consumer_token = '' #substitute values from twitter website
    consumer_secret = ''
    access_token = ''
    access_secret = ''

    auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
    auth.set_access_token(access_token,access_secret)

    api  = tweepy.API(auth)
    #print api.me().name
    #api.update_status('Hello -tweepy + oauth!')

    for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(2):
        print status.text+'\n'


if __name__ == '__main__':
    twitter_fetch('BBCNews',10)
Share:
10,579
Poru
Author by

Poru

Updated on June 13, 2022

Comments

  • Poru
    Poru almost 2 years

    I have problems with the new Twitter API: v1.0 is working without problems, but if I change the URL to v1.1 I get all the time a error "400 Bad request" (seen with Firebug).

    Example:

    https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi

    This is working like a charm, everything works as excepted. Simply changing the URL to .../1.1/... and I get a Bad request error and even to JSON error response or even some content at all.

    https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi

    Note: It couldn't be a rate limitation, because I accessed the URL the first time ever.

  • Poru
    Poru over 11 years
    In no browser I use (Firefox, Chrome) I'll be redirected. What browser do you use? 1 will be shut down on March 5th, 2013. It isn't the same like 1.1 - take a look over here: dev.twitter.com/blog/current-status-api-v1.1
  • Daniil Ryzhkov
    Daniil Ryzhkov over 11 years
    @Poru, Looks like a twitter API bug. Now I'm getting 400 Bad Request too.
  • Poru
    Poru over 11 years
    I think it was the missing user context + lib bugs. I switched my lib to Zend_Service_Twitter which works now.