Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

Re: Facebook API connection to Cascades/Native Development

Seems obvious now that you've pointed it out. I saw the local URL stuff but didn't realize it was critical to the operation.

 

The issue with Facebook is that it requires advance knowledge of the redirect_uri if it's not hosted on one of their servers. I created a little PHP script to work around that, as per the the WebWorks sample. I guess I can do one or both of a couple things -- ensure that PHP script redirects to the correct local URL and/or use a web view.

Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: Facebook API connection to Cascades/Native Development

[ Edited ]

I can't to get it worked too.The library doesn't handle the authorization. 

Here is my code:

KQOAuthParameters params;
params.insert("scope", "publish_stream,create_event,rsvp_event,offline_access,publish_checkins");
oauthManager->setHandleUserAuthorization(true);
oauthManager->getOauth2UserAuthorization(QUrl("http://m.facebook.com/dialog/oauth"), MY_APPLICATION_ID, params);

First it was unable to receive success answer from Facebook. Because it sends incorrect redirect_url paramenter. The library sets this parameter to : http://localhosl:XXXXX , where XXXXX - port number. This number always different. I changed my application settings Canvas URL to http://localhost:8080 and then change setupCallbackServer() function in library:

from :     return callbackServer->listen();

to:           return callbackServer->listen(QHostAddress::Any, 8080);

 

And now I get successfull authorization answer from Facebook. But library doesn't handle it. 

What wrong? Hot to get it worked? 

 

Thanks.

 

Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

Re: Facebook API connection to Cascades/Native Development

You can add your own redirect_url parameter and it should work. Ideally, take the one Facebook doesn't like out.

Then add a call to get the port number and give it to Facebook as the session state identifier. On an external server, use a php script like the one in the webworks example, buy modify it to use the URL the library wants, getting the port from the session state ID.

If you haven't connected to Facebook this way before, the other example might be simpler to follow. I used it with a webview and then parsed the auth token from the response as a proof of concept to have a working starting point. I had to take a break recently so haven't gone further. Not sure if I'll build on that or try to get the library working.
Highlighted
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Facebook API connection to Cascades/Native Development

In all honesty, OAuth2 doesnt really need a "library" to make requests since there isnt the complication of signing and special headers and all that jazz. The webview approach and parsing the token from the url is much easier.

Svat_ are you connecting the the appropriate signals to get the response? You can also turn on debug output in the library to see whats going on. I would not change the port and leave it the way it is. Facebook matches only on the host/path and doesnt care about the port. So in your application settings you can just put http://localhost then the library and its port assignments will do as they are supposed to.
Like all of my posts
Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: Facebook API connection to Cascades/Native Development

Hi kylefowler.

Thanks for you help! Facebook really matches host and port. You can try to open url in browser like:

http://facebook.com/dialog/oauth?client_id=XX_your_app_id_here_XX&response_type=token&redirect_uri=h...

with port and without ...  KQOAuthManager makes request with port. If your canvas url is http://localhost, facebook returns error page. 

 

I have it worked with my solution: run callback server on specified port and add this port to canvas url on application facebook setting page.

 

Best regards,

Svat_

Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

Re: Facebook API connection to Cascades/Native Development

Does facebook allow http://localhost? I was under the impression it didn't, but then maybe I was confusing that with it not allowing "local://".

Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: Facebook API connection to Cascades/Native Development

Yes, for example define http://localhost:65432/ in  facebook app settings, and then open callback server on this port (65432). It works fine.