Twitter v1.1: 400 Bad request

后端 未结 3 1303
有刺的猬
有刺的猬 2021-01-22 10:51

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).

相关标签:
3条回答
  • 2021-01-22 11:38

    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

    0 讨论(0)
  • 2021-01-22 11:38

    For me the cause was the size of the media that was attached to the tweet. If it was <1.2MB it went through OK, but if it was over, I would get a 400 error every time.

    Strange considering Twitter says the tweet limit is 3MB https://twittercommunity.com/t/getting-media-parameter-is-invalid-after-successfully-uploading-media/58354

    0 讨论(0)
  • 2021-01-22 11:47

    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)
    
    0 讨论(0)
提交回复
热议问题