首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用OAuth在兴兴与R

如何使用OAuth在兴兴与R
EN

Stack Overflow用户
提问于 2013-01-07 14:58:35
回答 1查看 2.5K关注 0票数 4

我正在尝试使用api.xing.com (v0.9.2)对XING (api.xing.com)进行身份验证。

代码语言:javascript
复制
library(package="RCurl")
library(package="ROAuth")

site <- "https://api.xing.com"
requestTokenPath <- "/v1/request_token"
accessTokenPath <- "/v1/access_token"
authorizePath <- "/v1/authorize"

consumerKey <- "***********"    # blank key for posting
consumerSecret <- "********"    # blank key for posting

requestURL <- paste(site, requestTokenPath, sep="")
accessURL <- paste(site, accessTokenPath, sep="")
authURL <- paste(site, authorizePath, sep="")

credentials <- OAuthFactory$new(consumerKey=consumerKey,
    consumerSecret=consumerSecret,
    requestURL=requestURL,
    accessURL=accessURL,
    authURL=authURL,
    needsVerifier=TRUE)

credentials$handshake(ssl.verifypeer=FALSE)  # skip ssl verification for testing, this is passed through to RCurl

输出:

代码语言:javascript
复制
Error in credentials$handshake(ssl.verifypeer = FALSE) : 
  Invalid response from site, please check your consumerKey and consumerSecret and try again.

我检查了我的键和URL,所以我很确定这不是错误的原因。

  1. 有人能告诉我我做错了什么吗?
  2. 是否有方法提取服务器请求和响应以进行错误分析?

谢谢,克里斯

EN

回答 1

Stack Overflow用户

发布于 2013-01-18 12:14:10

我建议使用Hadley的httr包,因为我发现它在处理API时特别有用。别忘了仔细阅读所有相关文件..。

它似乎使用了OAuth v1,所以请看相关的httr文档。

我不确定你是否已经认识this...but,这是一个两个阶段的过程.

首先,你把你的消费者钥匙和秘密发送到星,它会还给你一个令牌。

然后对所有这三个人:

( 1)使用者钥匙;( 2)使用者保密;( 3)刚才提供的令牌

但是,您能访问XING设置的所有API调用吗? up...you可能需要XML来高效地解释响应。

不确定这是否有效,但大致如下:

代码语言:javascript
复制
require(httr)
xing.app <- oauth_app("xing",key="xxxxxxxxxx", secret="xxxxxxxxxxxxxxx")
xing.urls <- oauth_endpoint(NULL, "authorize", "access_token",base_url = "https://api.xing.com/v1/")
xing.token <- oauth1.0_token(xing.urls, xing.app)
xing.token

xing.token中,该令牌用于该唯一的密钥和秘密组合,即user...but一旦有it...you就不需要一直请求it...you,可以将其存储在.Rprofile文件或something...and中,然后在GET或POST命令中将其作为选项引用。

代码语言:javascript
复制
user.signature <- sign_oauth1.0(xing.app, token = token.string.from.xing.token, token_secret = token.secret.from.xing.token)

# so I think as an example you can have this...
id <- "yyyyyyy"
GET(url= paste0("https://api.xing.com/v1/users/",id), config=user.signature)

希望helps....there可能是代码中的一些错误,因为这是没有测试的,因为我没有您的使用者密钥或秘密。我还没有完全看过文档,但我不认为太远了,off...please可以自由地重新使用corrections...when,您实际上是在测试它.

out of curiosity...what,您是否在使用API?

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14198411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档