如何在 R 中为 Tinder API 设置 RCurl headers
How to setup RCurl headers in R for Tinder API
这可能是一个愚蠢的问题,但出于某种原因,我无法理解 R 中的 RCurl headers 以访问 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))
我假设我的问题是 headers 和 here's what Tinder's API says about the headers。但它只是 returns Error: Forbidden
这对故障排除没有真正帮助。
关于我在这里做错了什么有什么建议吗?
试用新的且仍在改进的 curlconverter 包。你给它 curl 请求,它会为你创建一个 httr 脚本。我从你的 github link 那里拿走了这些。
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 magic
jsonlite::fromJSON(content(tinderResp, as = 'text'))
jsonlite::fromJSON(content(fbResp, as = 'text'))
这可能是一个愚蠢的问题,但出于某种原因,我无法理解 R 中的 RCurl headers 以访问 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))
我假设我的问题是 headers 和 here's what Tinder's API says about the headers。但它只是 returns Error: Forbidden
这对故障排除没有真正帮助。
关于我在这里做错了什么有什么建议吗?
试用新的且仍在改进的 curlconverter 包。你给它 curl 请求,它会为你创建一个 httr 脚本。我从你的 github link 那里拿走了这些。
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 magic
jsonlite::fromJSON(content(tinderResp, as = 'text'))
jsonlite::fromJSON(content(fbResp, as = 'text'))