我;正在努力使用httr
oauth2.0功能连接到Google Analytics(分析)
oauth2.0_token(oauth_endpoints("google")
, oauth_app("google", client.id, client.secret)
, scope = "https://www.googleapis.com/auth/analytics.readonly")
它可以在我的本地Rstudio中完美运行,但是在基于AWS的Rstudio Server中却无法使用。当我同意在浏览器中传递数据并且Google将我重定向到页面 http:// localhost:1410 /?state = codehere时,会出现错误
在本地Rstudio中启动身份验证时,浏览器会显示一条消息-身份验证完成。请关闭此页面并返回R,以防Rstudio服务器只是该网页不可用
我怀疑我需要更改listener_endpoint的配置,但是如何?我应该放置我的Rstudio服务器地址而不是默认的127.0.0.1吗?还是httr + Rtudio服务器的缺陷,我不应该理会?
你的重定向URI是问题的一部分。Httr的oauth2.0_token()函数可识别正确的函数。设置项目时,Google Analytics(分析)创建了两个重定向URI,一个可以在RStudio IDE(本地)上使用,另一个可以在基于RStudio Web的环境中用于带外身份验证: :ietf:wg:oauth:2.0:oob“
身份验证后,以下代码应该可以使用。
library(httr)
ga_id <- YourProjectID
client_id <- YourClientID
redirect_uri <- 'urn:ietf:wg:oauth:2.0:oob'
scope <- YourScope
client_secret <- YourSecret
response_type <-'code'
auth1 <- oauth2.0_token(
endpoint = oauth_endpoints("google"),
app = oauth_app(
"google",
key = client_id,
secret = client_secret
),
scope,
use_oob = TRUE,
cache = TRUE
)
-安