2012-09-22 60 views
1

我在使用新的Twitter API時遇到了問題:v1.0正常工作,但是如果我將URL更改爲v1.1,我總是得到一個錯誤「400錯誤的請求」 (看到Firebug)。Twitter v1.1:400不良請求

例子:

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

這是工作就像一個魅力,一切工作爲例外。 只需將URL更改爲.../1.1/...即可,並且我得到一個錯誤的請求錯誤,甚至是JSON錯誤響應甚至是一些內容。

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

注意:它不可能是一個速率限制,因爲我曾經訪問的URL的第一次。

回答

2

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi重定向我https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi

貌似1.1是一回事1

UPD:Looks like this is a rate limit(如1.1節2小時前爲我工作)。即使您第一次點擊API頁面,您的某些應用程序(descktop或移動設備)也可以使用API​​方法。

UPD2:1.1 400錯誤請求意味着你不autorized(https://dev.twitter.com/docs/error-codes-responseshttps://dev.twitter.com/docs/auth/oauth#user-context)。所以,你需要得到用戶上下文

+0

在任何瀏覽器中我使用(火狐,Chrome)我會被重定向。你使用什麼瀏覽器? '1'將在2013年3月5日關閉。它與'1.1'不一樣 - 請看這裏:https://dev.twitter.com/blog/current-status-api-v1。 1 – Poru

+0

@Poru,看起來像一個Twitter的API錯誤。現在我也得到'400 Bad Request'。 –

+0

@Poru,看看更新的答案 –

1

您需要進行身份驗證,並使用V1.1的API 下面是一些與蟒蛇tweepy工作之前使用OAuth授權 - 變狀態,從用戶的時間線

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)