R包用TwitteR设置Twitter API

时间:2014-06-02 18:39:11

标签: r macos twitter oauth

我正在尝试设置R的twitteR包以查询推文,并且不熟悉OAuth授权流程。类似于此的先前帖子没有表明有必要访问网站并输入数字字符串(这是我在尝试进行身份验证时收到的消息)。这个过程在去年有变化吗?现在,我需要在验证时输入accessTokenaccessSecret吗?

此前有关此主题的讨论如下:

ROAuth and twitteR, Mac OS X 10.7, R 2.15

TwitteR, ROAuth and Windows: register OK, but certificate verify failed

这是我正在使用的R代码和命令行响应:

> rm(list=ls())
> install.packages("twitteR")  
> install.packages("ROAuth")

> library("twitteR")
> library('ROAuth')

> requestURL <- "https://api.twitter.com/oauth/request_token"
> accessURL = "http://api.twitter.com/oauth/access_token"
> authURL = "http://api.twitter.com/oauth/authorize"
> consumerKey = "......................" # Generated by Twitter API: httl://twitter.com/apps/new 
> consumerSecret = "....................." # Generated by Twitter API
> Cred <- OAuthFactory$new(consumerKey=consumerKey,
                         consumerSecret=consumerSecret, 
                         requestURL=requestURL,
                         accessURL=accessURL, 
                         authURL=authURL)
> 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=w09UEcpe4FUiomnX4ZHxnRbIJOqSntd4JY0shu0xo
When complete, record the PIN given to you and provide it here:

> registerTwitterOAuth(Cred)

Error: Forbidden

我试图输入提供的代码,但这会产生相同的错误消息。有人遇到过这个问题吗?

系统信息: R版本3.1.0(2014-04-10) - “春之舞” 版权所有(C)2014 R统计计算基金会 平台:x86_64-apple-darwin13.1.0(64位)


更新(2014年6月3日):使用GitHub库来解决此问题

#install.packages(c("devtools", "rjson", "bit64")) # Intentional exclusion of ', "httr"'
# (2) Restart R
#install.packages("devtools")
library("devtools", lib.loc="/Users/wschram/Library/R/3.1/library")
devtools::install_github("hadley/httr")
library("httr", lib.loc="/Users/wschram/Library/R/3.1/library") # GitHub httr
install_github("twitteR", username="geoffjentry")
library(twitteR)

setup_twitter_oauth(API_Key, API_Secret, accessToken, accessSecret)
tweets <- searchTwitter('#beer', n=50)
head(tweets)

0 个答案:

没有答案