[英]twitteR Proxy Authentication with ROAuth
我正在嘗試使用來自RStudio的twitteR軟件包。
但是我收到一個錯誤:
“需要代理身份驗證”,有時候 - “無法找到主機”。
有許多線程具有相同的問題。
我已經嘗試了一切( - --internet2,R by setting "~/Rgui.exe" http_proxy=http:/999.99.99.99:8080/ http_proxy_user=ask
)。 但它沒有用。
在我的下面找到我的代碼(我從我的辦公室桌面,RStudio運行),這需要身份驗證: proxyuserpwd="**domain//username:pwd**"
。
我不確定這條線。 我試過各種組合,但都沒有效果。
rm(list=ls())
library(twitteR)
library(ROAuth)
library(RCurl)
options(RCurlOptions = list(
verbose = TRUE,
proxy ="http://proxy1.domain.com:8080",
proxyuserpwd="domain//username:pwd",
proxyauth="ntlm"))
reqURL <- "http://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- '.............'
consumerSecret <- '..........'
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
twitCred$handshake(cainfo="cacert.pem")
< Proxy-Authenticate: BASIC realm="Access to this server requires AD Authentication. Prefix your user ID with domain."
Host: api.twitter.com
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 221
Content-Type: application/x-www-form-urlencoded
Error: Proxy Authentication Required
> registerTwitterOAuth(twitCred)
< HTTP/1.1 407 Proxy Authentication Required
* Authentication problem. Ignoring this.
< Proxy-Authenticate: NTLM
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
* HTTP/1.1 proxy connection set close!
< Proxy-Connection: close
< Set-Cookie: BCSI-CS-3bf0ea03406bba28=2; Path=/
< Connection: close
< Content-Length: 899
<
* Closing connection #0
Error in registerTwitterOAuth(twitCred) :
oauth has not completed its handshake
但是當我嘗試使用以下代碼時。
library("RCurl")
opts <- list(
proxy = "proxy1.domain.com",
proxyusername = "domain",
proxypassword = "pwd",
proxyport = 8080
)
getURL("http://stackoverflow.com", .opts = opts)
......我很成功
>sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] twitteR_1.1.7 rjson_0.2.13 ROAuth_0.9.3 digest_0.6.3 RCurl_1.95-4.1 bitops_1.0-5
loaded via a namespace (and not attached):
[1] tools_2.15.1
我從這里嘗試了多線程解決方案,他們的解決方案都沒有用。 我不知道我在哪里犯了錯誤。(這是我需要用域名困擾我的域名嗎?)有人可以通過這個問題了解一下。
更新:
當我在RGui中運行相同的代碼(設置“〜/ Rgui.exe”http_proxy = http:/999.99.99.99:8080 / http_proxy_user = ask)時,它提示輸入用戶名和密碼來下載cacert.pem。
但是當我嘗試握手時,它會拋出同樣的錯誤:
錯誤:需要代理身份驗證。
更新:
我收到以下錯誤:
Error in function (type, msg, asError = TRUE) : Received HTTP code 407 from proxy after CONNECT
更新托馬斯建議 - 試過
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- '-----'
consumerSecret <- '-------'
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
h <- getCurlHandle(
proxy = "proxy1.domain.com",
proxyusername = "username", #but i have to always prefix my domain with username(Domain\username or domain\\username or domain//username)
proxypassword = "password",
proxyport = 8080,
cainfo = "cacert.pem")
twitCred$handshake(curl=h)
我收到以下錯誤
Error in strsplit(response, "&") : non-character argument
我正在用追溯輸出更新鏈接
5: strsplit(response, "&")
4: lapply(X = X, FUN = FUN, ...)
3: sapply(strsplit(response, "&")[[1]], strsplit, "=")
2: parseResponse(resp)
1: twitCred$handshake(curl = h)
謝謝托馬斯,為了你的幫助 - 我解決了這個問題。
rm(list=ls())
library(twitteR)
library(ROAuth)
library(RCurl)
reqURL <- "http://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- '-----'
consumerSecret <- '------'
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
h <- getCurlHandle(
proxy = "proxy1.domain.com",
proxyusername = "username",
proxypassword = "pwd",
proxyport = 8080, cainfo = "cacert.pem")
twitCred$handshake(curl=h)
To enable the connection, please direct your web browser to:
http://api.twitter.com/oauth/authorize?oauth_token=6VJ4mdc71BxVtgbI6YT0eNHqFCGe41f28MjiHl2KSvs When complete, record the PIN given to you and provide it here:
我用http取代了https
我真的對代理服務器一無所知,但為什么不為握手線嘗試這個(明確指定curl句柄):
h <- getCurlHandle(
proxy = "proxy1.domain.com",
proxyusername = "domain",
proxypassword = "pwd",
proxyport = 8080,
cainfo = "cacert.pem")
twitCred$handshake(curl=h)
我也在代理服務器后面工作,並且能夠使用以下代碼訪問twitter。
consumer_key <- '<put your consumer key here>'
consumer_secret <- '<put your consumer secret here>'
access_token <- "<put your access token here>"
access_secret <- "<put your access token secret here>"
set_config(use_proxy(url='proxy- address',port-number, username, password))
setup_twitter_oauth(consumer_key,consumer_secret, access_token , access_secret)
並且能夠獲取推文。 我還寫了一個博客,一步一步的程序來解決這個問題。 您可以從http://analyticsinall.blogspot.in/search/label/Analytics%20for%20Business訪問它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.