Skip to content
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
Closed

oauth2.0_token on Facebook returns error #324

tokumotion opened this issue Jan 20, 2016 · 5 comments

Comments

@tokumotion
Copy link

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
Copy link
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 as completed Jan 20, 2016
@tokumotion
Copy link
Author

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

@hadley
Copy link
Member

hadley commented Jan 21, 2016

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

@tokumotion
Copy link
Author

@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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants