2013-03-10 62 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