Skip to content

Instantly share code, notes, and snippets.

@masaha03
Created September 9, 2011 15:40
Show Gist options
  • Save masaha03/1206548 to your computer and use it in GitHub Desktop.
Save masaha03/1206548 to your computer and use it in GitHub Desktop.
twitteR & ROAuth
library(twitteR)
library(ROAuth)
requestURL <- "https://api.twitter.com/oauth/request_token"
authURL <- "https://api.twitter.com/oauth/authorize"
accessURL <- "https://api.twitter.com/oauth/access_token"
consumerKey <- "(Consumer key)"
consumerSecret <- "(Consumer secret)"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
# Windowsでは→をダウンロードして適当な場所に保存し, http://curl.haxx.se/ca/cacert.pem
# 以下を実行
# options(RCurlOptions = list(cainfo="(cacert.pemのパス)")))
twitCred$handshake()
registerTwitterOAuth(twitCred)
oauth <- twitteR:::getOAuth()
params <- list()
params[["status"]] <- "テスト"
url <- "https://api.twitter.com/1/statuses/update.json"
auth <- ROAuth:::signRequest(url, params, consumerKey, consumerSecret,
oauthKey = "(Access token)",
oauthSecret = "(Access token secret)",
httpMethod = "POST", signMethod = "HMAC")
params <- c(params, lapply(auth, I))
postForm(url, .params = params, curl=getCurlHandle(), style="POST")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment