Gabriele B
Gabriele B

Reputation: 2685

Error trying to connect to Facebook Graph API in R using http OAuth - "An access token is required to request this resource."

I'm trying to connect with Facebook Graph API using the httr package in R and following their example.

Here's the code I'm using:

library(httr)

myapp <- oauth_app("facebook", "1654022631546331", "<APP SECRET>")

facebook_token <- oauth2.0_token(oauth_endpoints("facebook"), myapp,
                                 type = "application/x-www-form-urlencoded",
                                 scope = "user_likes, user_photos, user_friends, user_about_me, read_stream, public_profile")

req <- GET("https://graph.facebook.com/9thcirclegames", config(verbose= TRUE, token = facebook_token))
str(content(req))

and I got this tracelog:

< HTTP/1.1 400 Bad Request
< WWW-Authenticate: OAuth "Facebook Platform" "invalid_token" "An access token is required to request this resource."
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=UTF-8
< X-FB-Trace-ID: EIYdwcrqLo7
< X-FB-Rev: 2063232
< Pragma: no-cache
< Cache-Control: no-store
< Facebook-API-Version: v2.0
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< X-FB-Debug: B2iCRCCYb9jg1sDNb0Hq7FbsF/Fp2x3ccSYN8djMQMYPa+/Y8ghR92f+KyJeFQiMC7K+teBVmtb2YsM3jdRoNw==
< Date: Thu, 26 Nov 2015 17:27:11 GMT
< Connection: keep-alive
< Content-Length: 139
< 

And when I try to inspect the facebook_token I got this instead:

> facebook_token
<Token>
<oauth_endpoint>
 authorize: https://www.facebook.com/dialog/oauth
 access:    https://graph.facebook.com/oauth/access_token
<oauth_app> facebook
  key:    1654022631546331
  secret: <hidden>
<credentials> {"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100,"fbtrace_id":"BOfrWTOEvDX"}}
---

These are two different errors I really don't understand. Have you any idea about that?

Upvotes: 1

Views: 760

Answers (1)

Gabriele B
Gabriele B

Reputation: 2685

I don't know why, but setting this before oauth2.0_token call solved the issue:

Sys.setenv("HTTR_SERVER_PORT" = "1410/")

Upvotes: 2

Related Questions