This is probably a stupid question, but for some reason I can't get my head around the RCurl headers in R in order to access an API. I'm trying to authenticate with the Tinder API, and have already authenticated to Facebook (using Rfacebook), but when authenticating to Tinder, all I get is Error: Forbidden
. Here's what I have so far (the last two lines is where I think the problem is):
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))
I'm assuming my problem is the headers, and here's what Tinder's API says about the headers. But it just returns Error: Forbidden
which isn't really helpful for troubleshooting.
Any suggestions about what I'm doing wrong here?
Try out the new and still improving curlconverter package. You give it the curl request and it creates an httr script for you. I took these from the github link you have.
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(`{` = ""))
Then you can copy and paste that result. So,
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(`{` = ""))
To get you json response work a little jsonlite magic
jsonlite::fromJSON(content(tinderResp, as = 'text'))
jsonlite::fromJSON(content(fbResp, as = 'text'))