New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oauth2.0_token on Facebook returns error #324

Closed
tokumotion opened this Issue Jan 20, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@tokumotion

tokumotion commented Jan 20, 2016

Hi, I've been trying to get my Facebook app token from httr using this code but got this message:

> app <- oauth_app('facebook', mktg_api_ID, mktg_api_secret)
> oauth2.0_token(oauth_endpoints("facebook"), app,
+ scope = '',
+ type  = "application/x-www-form-urlencoded")
<Token>
<oauth_endpoint>
 authorize: https://www.facebook.com/dialog/oauth
 access:    https://graph.facebook.com/oauth/access_token
<oauth_app> facebook
  key:    444682622372984
  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":"G+hjBKwmgHS"}}

Is this a package error or an app error?

@hadley

This comment has been minimized.

Member

hadley commented Jan 20, 2016

It's most likely that you didn't set the redirect url to oauth_callback()

@hadley hadley closed this Jan 20, 2016

@tokumotion

This comment has been minimized.

tokumotion commented Jan 21, 2016

@hadley I'm sorry, but how do I do that? Which is the redirect URL in this case?

@hadley

This comment has been minimized.

Member

hadley commented Jan 21, 2016

The redirect url is what you get when you run oauth_callback()

@tokumotion

This comment has been minimized.

tokumotion commented Jan 21, 2016

@hadley Set the redirect URL to the value oauth_callback() returns and got the same error. It opens the browser in http://localhost:1410/ with a success message, but R console returns error.

@msjgriffiths

This comment has been minimized.

msjgriffiths commented May 19, 2016

I also experienced this error.

The reason is that oauth_callback() return e.g. http://localhost:1410; but Facebook does not allow a URL without a trailing slash. That is, the URL should be http://localhost:1410/. If you attempt to enter http://localhost:1410 in the Facebook app settings, it adds the trailing slash.

I resolved this by monkey patching the function oauth_callback.

library(httr)
library(R.utils)
custom_oauth_callback <- function(){
    paste0("http://", Sys.getenv("HTTR_SERVER", "localhost"), 
                ":", Sys.getenv("HTTR_SERVER_PORT", "1410"), "/")
}
reassignInPackage("oauth_callback", "httr", custom_oauth_callback)

From there, it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment