2016-04-22 58 views
2

我正在嘗試使用twitteR庫檢索R中的許多用戶的推文。 setup_twitter_oauth和一些其他功能,如getUser,getFollowers都可以正常工作。我的問題是當我嘗試在lapply(或for循環)中使用userTimeline時,它給了我一個OAuth身份驗證錯誤。 (正確運行userTimeline。)在返回錯誤後,我使用getCurRateLimitInfo(),並且所有命令都顯示可用的限制。r twitter userTimeline錯誤oauth

這是我跑過的代碼片段。從(與回溯)lapply運行

... 
library("twitteR") 
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret) 
my_user <- getUser("my_twitter_name") 
my_followers <- my_user$getFollowers(n=100) 
tweets <- unlist(lapply(my_followers, function(x) userTimeline(x$id, n=100))) 

錯誤:

Error in twInterfaceObj$doAPICall(cmd, params, method, ...) : 

OAuth authentication error: 
This most likely means that you have incorrectly called setup_twitter_oauth()' 
10 stop("OAuth authentication error:\nThis most likely means that you have incorrectly called setup_twitter_oauth()'") 
9 twInterfaceObj$doAPICall(cmd, params, method, ...) 
8 doPagedAPICall(cmd, n, params, ...) 
7 lapply(X = X, FUN = FUN, ...) 
6 sapply(doPagedAPICall(cmd, n, params, ...), buildStatus) 
5 statusBase(cmd, params, n, 3200, ...) 
4 userTimeline(x$id, n = 100) 
3 FUN(X[[i]], ...) 
2 lapply(my_followers, function(x) userTimeline(x$id, n = 100)) 
1 unlist(lapply(my_followers, function(x) userTimeline(x$id, n = 100))) 

我沒有擡頭OAuth錯誤,它似乎setup_twitter_oauth時多發生,而不是其他的功能。幾個問題:

  • 是什麼導致了這個錯誤以及如何解決它?
  • 我的最終目標是從追隨者或持有追隨者用戶名和推文的數據框中獲取推文向量。有沒有更有效的方法來實現這一目標?

謝謝!

回答

2

我有同樣的問題。刪除受保護的用戶解決了它。 嘗試類似my_followers <- my_followers[protected == FALSE],它應該工作。