2013-03-10 59 views
0

我想將R連接到Twitter。 我按照步驟設置我們在這裏: http://cran.r-project.org/web/packages/twitteR/vignettes/twitteR.pdf無法使用ROauth獲取PIN碼

,我有如下代碼:

library(ROAuth) 
cred <- OAuthFactory$new(consumerKey="xyz", 
consumerSecret=xyz", 
requestURL="https://api.twitter.com/oauth/request_token", 
accessURL="https://api.twitter.com/oauth/authorize", 
authURL="https://api.twitter.com/oauth/access_token") 
cred$handshake(ssl.verifypeer = FALSE) 

當我得到Twitter的鏈接: https://api.twitter.com/oauth/access_token?oauth_token=YZZOYJ1liH1TDEY8G6Eb3YmgAWQlgGiEfAzI1ADwZ4

,並加載它我它會返回一個空白頁面,但沒有關於PIN的信息。誰能告訴我爲什麼這個鏈接是空白的

回答

0

因爲您訪問的網址是錯誤的authroize。交換你的authaccess網址!

accessURL="https://api.twitter.com/oauth/access_token", 
authURL="https://api.twitter.com/oauth/authorize") 

#You should get... 
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")) 
To enable the connection, please direct your web browser to: 
http://api.twitter.com/oauth/authorize?oauth_token=someaccessstokenvalue 
When complete, record the PIN given to you and provide it here: 

#Final step to register connections 
registerTwitterOAuth(Cred) 
+0

SimonO101,謝謝你的幫助。我覺得真的很愚蠢,但我正試圖抓住這個R包。我可以問你爲什麼改變了下面的代碼嗎?有什麼好處'Cred $ handshake(cainfo = system.file(「CurlSSL」,「cacert.pem」,package =「RCurl」))' – user1966593 2013-03-10 20:08:00

+0

沒問題! 'cainfo'位告訴系統在哪裏查找由'RCurl'提供的特定cacert文件。 'cacert'文件包含公共證書頒發機構的證書,您的系統使用這些證書來驗證稱爲自己Twitter的服務器真的是它所說的。有時,Curl使用的默認文件可能會過時,系統無法驗證從服務器接收到的證書。 (這往往發生在Windows系統上)。 – 2013-03-10 22:53:25

+0

而且不要覺得愚蠢!我們都應該嘗試每天學習更多。 – 2013-03-10 22:54:45