Facebook Connect

460 views
Skip to first unread message

Peter

unread,
Jun 21, 2011, 1:17:54 PM6/21/11
to rhomobile
Trying to do a FB Connect to get user info and post to stream.

Button to call Action:

fb_app_id = "xxxxxxxx"
call_back_url = url_for(:controller => "Settings", :action
=> :fb_initiate_login_callback)
feature_requests = "scope=email,read_stream"
url = "http://m.facebook.com/dialog/oauth?client_id=#{fb_app_id}
&redirect_uri=#{call_back_url}&#{feature_requests}&display=touch"
WebView.navigate(url)

But all this gets me is "An error occurred with APP_NAME. Please Try
again later." Any ideas?

evgeny vovchenko

unread,
Jun 22, 2011, 5:47:17 AM6/22/11
to rhom...@googlegroups.com
try to url encode all parameters:

url = "http://m.facebook.com/dialog/oauth?client_id=#{
Rho::RhoSupport.url_encode(fb_app_id)}
&redirect_uri=#{ Rho::RhoSupport.url_encode(call_back_url)}&#{
Rho::RhoSupport.url_encode(feature_requests)}&display=touch"


http://docs.rhomobile.com/rhodes/application#rhosupport-class

Button to call Action:

--
You received this message because you are subscribed to the Google Groups
"rhomobile" group.
To post to this group, send email to rhom...@googlegroups.com.
To unsubscribe from this group, send email to
rhomobile+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rhomobile?hl=en.

Raúl Alejandro Véjar Llugany

unread,
Jun 23, 2011, 5:07:37 PM6/23/11
to rhom...@googlegroups.com
Has anyone out there been able to get facebook dialogs working with Rhodes?
 
To me there seems to be 2 problems:
 
1) The facebook app is rejecting call_back_url that are not part of the website defined in the facebook app's profile.
 
2) The redirect that facebook does after the user is done dealing with the dialog is missinterpreted by facebook to be "http:m.facebook.com/app/theaddress" since url_for returns a relative address for the rhomobile application

I will look into the old branch where facebook connect was working to see how these issues where dealt with, but I would love for someone that has actually get it to work to share their facebook app profile configuration and what urls they are sending to the facebook api

Peter

unread,
Jun 23, 2011, 6:06:39 PM6/23/11
to rhomobile
Tried as you suggested, think I have it narrowed down.

Problem is that need to use "http://127.0.0.1/
#{System.get_property('rhodes_port')}/app/Settings/
fb_initiate_login_callback as url.

If I remove port number from redirect_uri facebook process continues.

From what I see I have 3 options
- 1. Can I make port static?
- 2. pass the port number to redirect_uri -> send user to my
webserver -> have my webserver catch the port and launch a redirect to
the other view passing the code -> request token (don't know if will
have to do this circle again.)
- 3. Something simpler that anyone can recommend?

Peter

unread,
Jun 24, 2011, 11:04:16 AM6/24/11
to rhomobile
Typo - http://127.0.0.1/#{System.get_property('rhodes_port')}/app/Settings/fb_initiate_login_callback

Should be http://127.0.0.1:#{System.get_property('rhodes_port')}/app/Settings/fb_initiate_login_callback

Peter

unread,
Jun 25, 2011, 3:21:38 PM6/25/11
to rhomobile
Ok, so made some progress but could really use some advice here. Was
able to get auth_token, at a price.

Had to set local_server_port to 12345 and in facebook settings had to
set the site url to http://127.0.0.1:12345 for things to work.

On one side everything works, on the flip-side after some looking
around found out this is not a valid solution.

Is anyone using facebook connect with there oauth dialog in rhodes?
any pointers?

I did find out that if I put fb#{my_app_id}://authorize/ in the
rediect_uri facebook will ignore the site url and return back the code
in -> SimpleMainView| Open url in external application:
fbXXXXXXXXXX://authorize/?code=X4_d1axSHEzkndck

Is there a way to catch this response? Running out of ideas. :(

DaveM

unread,
Jun 25, 2011, 6:46:36 PM6/25/11
to rhom...@googlegroups.com
I'm currently trying to get the oauth2 gem to play nicely with Rhodes, but an getting a little bogged down in dependancy hell. Has everyone already tried and abandoned this route, or have you all succeeded where I'm failing?

Peter

unread,
Jun 25, 2011, 7:18:21 PM6/25/11
to rhomobile
Nope.

Am communicating with foursqare api v2 and oauth2 since they are
little more lenient with not caring about what port I'm using but
facebook is proving to be a beast.

So far only way I can talk with facebook is by forcing rhomobile port.

Are you looking to integrate with facebook to or other?

DaveM

unread,
Jun 26, 2011, 3:47:32 AM6/26/11
to rhom...@googlegroups.com
I'm wanting to integrate with both facebook and foursquare, but ultimately (from what I understand) with a general oauth2 integration, it really shouldn't matter which service I'm integrating against, as it should "just work".

- D.

Peter Casanova

unread,
Jun 26, 2011, 10:23:59 AM6/26/11
to rhom...@googlegroups.com
It should.

I have it working with foursquare doing calls for auth and searching, but fb is a bit harder cause of the port.

If you figure out how to get it to work with ouath, please let me know.


On Jun 26, 2011, at 3:47 AM, DaveM wrote:

I'm wanting to integrate with both facebook and foursquare, but ultimately (from what I understand) with a general oauth2 integration, it really shouldn't matter which service I'm integrating against, as it should "just work".

- D.

--
You received this message because you are subscribed to the Google Groups "rhomobile" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhomobile/-/0uEebSoc76cJ.

Peter Casanova

unread,
Jun 28, 2011, 8:48:39 AM6/28/11
to rhom...@googlegroups.com
Dave where you able to get it to work?


On Jun 26, 2011, at 3:47 AM, DaveM wrote:

I'm wanting to integrate with both facebook and foursquare, but ultimately (from what I understand) with a general oauth2 integration, it really shouldn't matter which service I'm integrating against, as it should "just work".

- D.

Peter

unread,
Jun 28, 2011, 10:57:29 AM6/28/11
to rhomobile
Is there a way to catch the url in "Open url in external application"
with rhomobile?

I see it in the log file, so hoping that I can.

Alexey Tikhvinsky

unread,
Jun 28, 2011, 12:52:27 PM6/28/11
to rhom...@googlegroups.com
Hi

what do you mean under 'to catch the url in "Open url in external application"'?

If you describe what you exactly need I will try to help.

-alexey


--
You received this message because you are subscribed to the Google Groups "rhomobile" group.

Peter Casanova

unread,
Jun 28, 2011, 1:22:34 PM6/28/11
to rhom...@googlegroups.com
Please.  Really need help here.

Facebook requires that the redirect_uri start with my site http:www.mysite.com or it will put it there automatically.

In my controller action I have 
def fb_initiate_connect
  fb_app_id = "xxxxxxxxxxx"
  call_back_url = "app/Settings/fb_login_callback"
  feature_requests = "scope=email,read_stream"
  WebView.navigate(url)
  # Something to catch redirected url
end

I look at my log file when all this happens and see:
APP | RHO serve: /app/Settings/fb_initiate_connect
HttpServer | Process URI: '/system/redirect_to'
SimpleMainView | Open url in external application: http://www.mysite.com/app/Settings/fb_login_callback?code=5OruTD....

In between HttpServer and SimpleMainView is where facebook does at its authentication and request for permission.  SimpleMainView is the response from facebook with code, error, etc.

Is there a way in my fb_initiate_connect to "listen" for this response which is being logged?

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 1:42:24 PM6/28/11
to rhom...@googlegroups.com
Peter and I are trying to figure out a way to work with facebook's API redirect design (instead of return a result it redirects to an address but requiring that the website and port are preconfigured inside your facebook's app configuration for security reasons) . So what Peter is trying to do is "catch" the redirect facebook does after the oauth is processed and handle it in a controller somewhere in the mobile app.
I'm trying to do something similar by pointing Facebook to use a redirectme.to address that points back to the local app address with the dynamic port assigned by rhodes but I'm still getting problems from Facebook's api saying the url is not valid for my app
 
I've actually started experimenting on using Facebook's javascript API instead, but the thing is failing silently and I suspect it's for the same reasons so seems like a dead end there too...

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 2:22:28 PM6/28/11
to rhom...@googlegroups.com
Ok, I solved it, I had a stupid typo on the facebook app's configuration
 
The problem: When connecting to facebook using the dialogs, or oauth services, you must provide a callback url that must match the beginning of what you define as your 'Site URL' on your Facebook App settings. Problem is Rhodes assign a random port number on application startup and even though it is possible to make this a fixed number it is not desirable since another rhodes app might be running in background and conflict with the same port number or it might conflict with another service in the phone.
 
The not so ideal solution: Use a redirect service to dynamically pick the port that Rhodes is using and getting the redirect you need.
Redirectme.to is a website that provides a free redirect service allowing you to define which address you wish to be redirected to
In this example i'm going to use the dialog's service to post a message in the user's wall
 
Then you can have a link as follows:
 
Share the fun on facebook: <a target="_webapp" href="<%= url + "&message=#{Rho::RhoSupport.url_encode("I\'m having an awesome time on this app!")}" %>">Share</a>
 
The downside: your app might be abused by other people that know your app_id and want to use your app to redirect traffic to a phishing site or something worse
 
More ideal solution: build a redirect page in a website you own that only allows you to redirect to a localhost address and put this as the site url in your facebook app hence making it impossible to redirect to other websites. Slightly expensive though since you need to host this somewhere.
This should also work for oauth or any other url-type service of facebook
 
Hopes it helps others with the same problem

 
2011/6/28 Raúl Alejandro Véjar Llugany <raul....@gmail.com>

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 2:41:02 PM6/28/11
to rhom...@googlegroups.com
Replace www.facebook.com for m.facebook.com to get the nicer mobile optimized webpages

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 3:08:57 PM6/28/11
to rhom...@googlegroups.com
Addendum, if you use the m.facebook.com address you might run into the infamous "error code 3: This method isn't supported for this display type"
 
this is a known bug with facebook on Android and iOS (also the Rhodes emulator), hopefully to be fixed soon:
 

The temporary fix seems to be to use the normal www address on popup mode

Alexey Tikhvinsky

unread,
Jun 28, 2011, 3:34:38 PM6/28/11
to rhom...@googlegroups.com
Guys,

You can use slightly more simple aproaches:

1. to use AsyncHttp methods:

Rho::AsyncHttp.get(:url => 'http://m.facebook.com/dialog/oauth?client_id....bla-bla-bla', :callback => (url_for :action => :your_callback))

I am not familiar with FB protocol... This will work if the request returns a redirect response non interactivly...

2. Use "deep linking" feature.

Use your application URI as redirect_uri param or your request to FB.
The application URI can be of two kinds:
-http
-castom scheme

Http is default. In this case use your application java package as host like http://com.myorganization.appname
Custom scheme may be registered at build.yml as android: bundleURLScheme: myscheme
in this case you can set redirect_uri="myscheme:///app/controller" or something like this...

This will work in case FB first want to show some page to user and redirects to redirect_uri after some user interactions. The main restriction that FB server should use redirect response. In another case Android browser will not follow it...


In any case both solutions will avoid you from host/port problems you discussed above.

-alexey

Alexey Tikhvinsky

unread,
Jun 28, 2011, 3:37:28 PM6/28/11
to rhom...@googlegroups.com

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 3:41:49 PM6/28/11
to rhom...@googlegroups.com
I require a solution that works across as many platforms as possible, as per documentation your suggestion will only work on Android and iOS and it would require custom code per platform to accomplish or I'm completely misunderstanding something in your email?

Alexey Tikhvinsky

unread,
Jun 28, 2011, 3:50:13 PM6/28/11
to rhom...@googlegroups.com
Yes, "deep linking" is supported on iOS and Android for the moment.
AsyncHttp works everywhere.

Peter Casanova

unread,
Jun 28, 2011, 4:11:51 PM6/28/11
to rhom...@googlegroups.com
Maybe I'm missing something.

Let's say we setup our BundleURLScheme for both android and ios 
iphone:
  BundleIdentifier: com.rhomobile.myapp
  BundleURLScheme: myapp
android
  BundleURLScheme: myapp

and lets say that are target callback is /app/Controller/action

if android this would = myapp://app/Controller/action
where in ios it would be = myapp:app/Controller/action

Raúl Alejandro Véjar Llugany

unread,
Jun 28, 2011, 4:32:27 PM6/28/11
to rhom...@googlegroups.com
These methods (dialogs, oauth) don't return a response, they take control of the application and provide their own pages to log the user in and authorize the app if needed, that's why they have a callback url so they can give back control once the process is complete. The asynchttp call won't do any good in this scenario

Alexey Tikhvinsky

unread,
Jun 28, 2011, 4:44:07 PM6/28/11
to rhom...@googlegroups.com
For android it is important to have a valid URI and for iOS it does not matter (just scheme).
You can use myapp:///app/Controller/action in both Android and iOS
Note about 3 slashes in case no host provided.

At both platforms you need to track System.get_start_params() manually. It will change as app invoked by its URI. This is string with the URI without the scheme.

-alexey

Peter Casanova

unread,
Jun 28, 2011, 7:10:05 PM6/28/11
to rhom...@googlegroups.com
You lost me at:
At both platforms you need to track System.get_start_params() manually. It will change as app invoked by its URI.

Only problem I see is that this scheme is not allowed by facebook.  AFAIK

this gives "an error occurred..."  Basically, url is not allowed
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.

Just out of curiosity, can we get access to the response that rho logs with SimpleMainView | Open url in external application :response_from_fb in the current controller action?

So far here is what I've got -neither a really good solution for me, but working.
option 1 - force port on facebook and rho (not really a valid solution and requires 2 facebook apps)
option 2 - redirect back to my site and re-launch rhodes from there
option 3 - use redirectme.to solution that Raul is using, easier than option 2 and probably better (for me, requires 2 facebook apps though)

I am trying to get access to the last call in my rholog file. SimpleMainView | Open url in external application :the response from facebook.  If so, then we can enter the correct url in the call back, i.e. http://www.mysite.com, listen for this, strip it from response and what ever follows would be the real redirect and response from server.

Advantage - 1 app for facebook and open the door to other oauth providers.

But maybe someone has a better solution.  

DaveM

unread,
Jun 29, 2011, 2:22:30 AM6/29/11
to rhomobile
Sorry for the late reply - nope, not yet. I went down a different tack
last night, and tried to get the FBConnect code from the 1.5 branch
building as a native extension within my app, but as yet still no joy.
I guess it doesn't help that my coding chops are really rusty, and I'm
completely new to ruby / rhodes framework.


On Jun 28, 2:48 pm, Peter Casanova <pe...@onsitevidworks.com> wrote:
> Dave where you able to get it to work?
>
> On Jun 26, 2011, at 3:47 AM, DaveM wrote:
>
>
>
>
>
>
>
> > I'm wanting to integrate with both facebook and foursquare, but ultimately (from what I understand) with a general oauth2 integration, it really shouldn't matter which service I'm integrating against, as it should "just work".
>
> > - D.
>
> > --
> > You received this message because you are subscribed to the Google Groups "rhomobile" group.
> > To view this discussion on the web visithttps://groups.google.com/d/msg/rhomobile/-/0uEebSoc76cJ.

Peter

unread,
Jun 29, 2011, 10:10:26 AM6/29/11
to rhomobile
Rho gurus, I have a question.

For facebook, don't think scheme will work since only certain scheme's
are allowed.

After looking at facebook ios/android sdk, foursquare, etc. they all
put a "listener" for the redirect.

Can we do the same with Rho? or something similar? Maybe read log
file and look for next time entry is made?

https://github.com/facebook/facebook-ios-sdk/blob/master/src/Facebook.m
line 301 - 341

https://github.com/foursquare/android-oauth-example/blob/master/workspace/android-oauth-example/src/com/foursquare/android/oauth/ActivityWebView.java
line 47 and below
Reply all
Reply to author
Forward
0 new messages