如何在R中为Tinder API设置RCurl标头

时间:2016-02-14 23:53:59

标签: r rcurl

这可能是一个愚蠢的问题,但出于某种原因,我无法理解R中的RCurl标题以访问API。我尝试使用Tinder API进行身份验证,并且已经通过Facebook身份验证(使用Rfacebook),但在向Tinder进行身份验证时,我得到的只是Error: Forbidden。这是我到目前为止(最后两行是我认为问题所在的地方):

library(Rfacebook)
library(devtools)
library(RCurl)

appID<-'MYAPPID'
appSecret<-'MYAPPSECRET'

fb_oauth <- fbOAuth(app_id=appID, app_secret=appSecret)
me <- getUsers("me",token=fb_oauth)
fbID <- me$id

save(fb_oauth,file="fb_oauth")
load("fb_oauth")

my_Token <- toString(fb_oauth$credentials)
my_httpheader <- c("Content-type='application/json', User-agent='User-Agent: Tinder/3.0.4'")

myTest <- postForm("https://api.gotinder.com/auth", facebook_id=fbID, facebook_token=my_Token, .opts=list(httpheader=my_httpheader))

我假设我的问题是标题,here's what Tinder's API says about the headers。但它只返回Error: Forbidden,这对于排除故障并不是很有帮助。

关于我在这里做错了什么的任何建议?

1 个答案:

答案 0 :(得分:2)

试用新的仍在改进的curlconverter软件包。你给它curl请求,它会为你创建一个httr脚本。我从你的github链接中获取了这些。

library(curlconverter)

fbPost <- "curl -X POST https://api.gotinder.com/auth --data '{\"facebook_token\": fb_token, \"facebook_id\": fb_user_id}'"

tinderPost <- "curl -X POST https://api.tinder.com/profile --data '{\"age_filter_min\": 26, \"gender\": 1, \"age_filter_max\": 32, \"distance_filter\": 14}'"

fb <- make_req(straighten(fbPost))
fb
# [[1]]
# function () 
# httr::VERB(verb = "POST", url = "https://api.gotinder.com/auth", 
#     body = list(`{` = ""))

tinder <- make_req(straighten(tinderPost))
tinder

# [[1]]
# function () 
# httr::VERB(verb = "POST", url = "https://api.tinder.com/profile", 
#     body = list(`{` = ""))

然后您可以复制并粘贴该结果。所以,

fbResp <- httr::VERB(verb = "POST", url = "https://api.gotinder.com/auth", 
    body = list(`{` = ""))

tinderResp <- httr::VERB(verb = "POST", url = "https://api.tinder.com/profile", 
    body = list(`{` = ""))

为了让你的json响应工作有点jsonlite魔法

jsonlite::fromJSON(content(tinderResp, as = 'text'))
jsonlite::fromJSON(content(fbResp, as = 'text'))