Error in Facebook Connect with Devise on Rails - facebook

I have spent a few hours trying to debug this issue and while there are several answers I couldn't get this to work and don't understand a few things.
I have Facebook login implemented with Devise on my Rails 3 App deployed on Heroku. I have this working fine on localhost and I had this working on production as well. I don't think I changed anything but I found out that the Facebook login was broken and can't figure out how to fix this. A few clues that may ring a bell for some -
The url I am getting where the error shows is below with the error message that many others posts show. What I find strange is the following -
Decoding the url below the redirect_uri has a port number http://www.mygreenneighbor.com:24745/auth/facebook/callback&scope=email,offline_access&
I don't think the app on Heroku is listening at this port 24745 (which btw changes when I try it after sometime) and I haven't noticed that before - is that expected?
When I make changes to my Facebook app and change the site url that change doesn't show up in the redirect uri. Does it take time for FB changes to take effect?
https://graph.facebook.com/oauth/authorize?client_id=159903734070492&redirect_uri=http%3A%2F%2Fwww.mygreenneighbor.com%3A24745%2Fauth%2Ffacebook%2Fcallback&scope=email%2Coffline_access&response_type=code
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
Thanks for your thoughts/guidance.
-S

After a lot of digging around, I cam across this article
http://www.kbedell.com/2011/03/08/overriding-omniauth-callback-url-for-twitter-or-facebook-oath-processing/
I realized that I had switched to using Passenger as my web server from a singled threaded/process WebRick webserver. Passenger has more than one process running on the same dyno and apparently it sends a callback url with a port number in the request. To override that I used the advice in the above article and set the following in my applicaiton.rb file
OmniAuth.config.full_host = "http://www.mygreenneighbor.com" and it solved the problem.
Hope this helps someone.
-S

Related

Facebook Test User error

I use facebook login in my app and have tests for it. I use the /{app-id}/accounts/test-users endpoint to create users for my tests but the endpoint fails with the very generic
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
(which says the API is possibly down). I tried this with 3 different appids/secrets, both with using app_id|app_secret as the token and with a token from the get token endpoint. I also tested this on the Graph Api Explorer and it's giving me the same error. It was working fine but then it suddenly stopped.
What I want to know is 1. is it down? and 2. if not, what did i do wrong or what changed since yesterday?
+1 this also started to me yesterday mid-morning, with code and an FB app which had been working previously and was unchanged.
When I look at https://developers.facebook.com/apps/FB_APP_ID/roles/test-users/, I can see the new users.
So the call is "working" in that new users are being created, but it is broken in that we get a 500 and we don't get an access_token.
I don't have an answer yet.
I ran into a similar problem last week. After long hours of debugging I found out that I would get this same error every time I tried to create multiple test users with the same name simultaneously (i.e. when running tests in multiple threads).
So instead of setting custom a user name I don't even use the name field and I just let Facebook generate one. This way everything works fine. Seriously. I love Facebook API so much. :)
Hope this helps someone.

Facebook Page feed not accessible via JS SDK nor Graph API

I'm recently experiencing troubles with a company page at Facebook. I used to access the https://graph.facebook.com/[page alias]/feed url (providing an access token of course). It has been working for months now and it suddenly stopped.
The JSON I get is the following:
{
message: "An unexpected error has occurred. Please retry your request later.",
type: "OAuthException",
code: 2
}
It stopped working the day/night after the page posted a status containing a link (in terms of Facebook graph), and also it contained 3 bit.ly links. I have the assumption that the (whole!) feed got blocked because of this, as this could be considered spamming ... It's a serious website, though!
Any tips on this? I found this on the internet: http://support.conversocial.com/entries/23482331-Known-issue-Facebook-Shortened-URLs-such-as-bit-ly
My advice would be to remove the post containing those links and - hope - that it gets "enabled" at some time - but it would be disappointing if not, of course :)

Facebook login only works when hosts is set to localhost?

Unfortunately I keep getting this error:
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
Login works however when my /etc/hosts file is set to: 127.0.0.1 [mysite].rhcloud.com, it only fails when I view the actual [mysite].rhcloud.com.
I am running the exact same application (on a different server) locally as the one I'm running on rhcloud. Specifically the local<->remote web-application directories are synced.
URL information
When attempting login remotely the URL looks like this; and fails with aforementioned error:
https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F[mypublicipaddress]%2Fuser%2Flogin&response_type=code&client_id=[hidden]
Whereas attempting to login locally the URL looks like this; and works:
https://www.facebook.com/dialog/permissions.request?app_id=[hidden]&display=page&next=http%3A%2F%2F[hidden].rhcloud.com%2Fuser%2Flogin&response_type=code&perms=user_photos%2Cfriends_photos&fbconnect=1
OK, you seem to be doing this right, but there's one thing that sometimes trips people up, do both your redirect_uri and 'Website URL' field have a trailing '/'?
In particular, if the redirect_uri doesn't have the trailing '/' (or a filename, etc) after the domain name it doesn't always work
did you set your canvas URL/secure canvas URL in facebook app configuration. IF so, retry after removing them. Or try after making sure canvas URL should be correct.
Yes. The trailing / matters. Just check your these fields, and add that trailing / if it's not there.
But, to be honest, this is the first time I've seen something like this. Usually, we see Facebook logins failing on a local environment, but working just fine in production.
I was able to overcome exactly the same problem by accessing my facebook developer application account and changing the domain from localhost to the url of my application

Facebook app oauth dialog error

I've been searching for the answer for days and I haven't been successful so I finally post to ask.
I'm developing a facebook app locally (it says I can develop locally in the guide) and having an issue when trying to authorize the app.
The following is the error msg I get when I direct to http://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=https://apps.facebook.com/MY_APP_NAME
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Error
An error occurred with Footmarker. Please try again later.
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Canvas URL & Site URL : http://localhost:8888/app/
I'm using EasyPHP hence port 8888. I tried changing port number to 80(default), 8080(one used in facebook guide) and no success.
I don't know if it's EasyPHP that causes the problem or simply I'm doing something wrong.
This thing drives me crazy. Help much appreciated. Thanks.
in this url: http://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=https://apps.facebook.com/MY_APP_NAME
You have to set redirect_uri=http://localhost:8888/app and authorize the localhost domain in your facebook app's settings (in the App domains field).
The Site URL & Canvas URL are used to check if the redirect_uri is not set to another URL for security reasons but the standard specify redirect_uri so they've let this parameter.
It's for this kind of error I built OAuth.io. We don't want more developers like you with a headache using OAuth.
using it is really easy:
OAuth.popup('facebook', function(err, res) {
// here, you can use res.access_token to make your API Call
// or...
res.get('/me')
.done(function(data) {
alert('Hello ' + data.name)
})
})
With this, you can't make mistake with URL anymore :)
The problem here is that your URL is not on the Internet. It is accessible from your computer only. You need a public URL.
Perhaps you can use dynDNS free to get onto the Net with your application from home.
Or, get a web server connected to the Net to host your App.
Best of luck!
this just because of URL mistake
whatever website url is specified should be correct.
i mentioned website url as http://localhost:3000/ and domain as localhost
but in my browser i was running http://0.0.0.0:3000/ that was the actual problem so i ran server as localhost:3000 now its working fine. Because we mentioned site url as localhost fb will redirect to same, if we r running 0.0.0.0:3000 it will rise error that Given URL is not allowed by the Application configuration.
so becarefull with your website url you have specified in facebook app.
and the url you are running locally both should match
thank you

facebook OpenGraph API on Rails (FBGraph)

I am trying to use FBGraph to let my app publish messages on the users wall. However, all of the APIs are kind of foreign to me and I am just trying to change things and see what happens. Right now, I am getting this error message
{
"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration."
}
}
Does anyone know what it means by redirect_uri? What would it be on my Application Settings page on facebook?
Florin is correct. Just a note here.. when testing locally you will need to set it to:
http://localhost:3000/ (or whatever your app server port is)
Then when you move it to production, set it to your regular URL:
http://yourdomain.com/
I have a separate facebook app that I use in development to test, so I don't have to change back and forth between them and I set up the keys in a settings file, which has my tokens for development and production apps.
Anyways, looks like you are almost there. It is making it back to the callback url at least. Should be fine once you update the facebook_connect URL
I am not a facebook expert, but I hit the exact same problem as you a few hours ago when I was trying to login a user inside a web application with Facebook.
It seems that the redirect_uri which you specify in your call to "https://graph.facebook.com/oauth/authorize" must be on the same domain as the Connect Url of your application. (you can set that connect url from the Connect section in your application's settings)
Regards,
Florin
May need to check your Settings > Basic > Basic Info > App Domain. I believe hat needs to be set correctly for the redirect_uri as well.
I had the same issue.
In my case, I had configured site url on facebook as: "http://localhost:3000", it was a wrong URL to facebook.
The reason is, it lack of the / in the end of url, so the correct site url should be:
"http://localhost:3000/"
Just verify your 'Application ID'. In my case I had that problem because I was using ID from my other project that I was working on. Fairly obvious but I lost some time.
I had to make sure I had the scope in there too:
config.omniauth :facebook, 'xxxx', 'xxx', :scope => 'offline_access,email,publish_stream'
Plus you really need to make sure you wait a couple of minutes because it does take time to propagate..