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
Contributor
mrmartis
Posts: 33
Registered: ‎08-24-2012
My Carrier: Bell

Facebook API connection to Cascades/Native Development

Hello fellow developers, 

I am building an app that uses Facebook's graph api and I am wondering if it is possible to connect the app to my app in Cascades development or is the only way to do it in HTML5 development?

I need to be able to use the graph api to login into facebook, and pull down a users facebook friends and store it in my application. Please let me know if there is a way to do this in Native Development?

Thanks

Please use plain text.
Contributor
mrmartis
Posts: 33
Registered: ‎08-24-2012
My Carrier: Bell

Re: Facebook API connection to Cascades/Native Development

I come from a web development background, and have worked with the Facebook Graph API before. Although, I want to build my bb10 app with cascades and native development so it can have that native blackberry feel. I just never done it before and was wondering if anyone can help walk me through the process. 

 

Thanks

Ash

Please use plain text.
Developer
kylefowler
Posts: 525
Registered: ‎05-17-2009
My Carrier: ATT

Re: Facebook API connection to Cascades/Native Development

Check out this library https://github.com/blackberry/bb-cascades-oauth
Like all of my posts
Please use plain text.
Regular Visitor
erboulay
Posts: 1
Registered: ‎01-23-2013
My Carrier: -

Re: Facebook API connection to Cascades/Native Development

Is there any sample using this library available?

 

Please use plain text.
Trusted Contributor
kunal_one
Posts: 125
Registered: ‎12-23-2012
My Carrier: wifi

Re: Facebook API connection to Cascades/Native Development

Sometime back I wrote sample code to post comment on user's wall usin Qt.

 

following post described the same

 

http://kunalmaemo.blogspot.kr/2012/01/posting-on-facebook-wall-from-qt.html

 

following post describe how we can upload picture.

 

http://kunalmaemo.blogspot.kr/2012/04/upload-photo-on-facebook-using-qt.html

Please use plain text.
Developer
kylefowler
Posts: 525
Registered: ‎05-17-2009
My Carrier: ATT

Re: Facebook API connection to Cascades/Native Development

Its basically the same way to do facebook as in the foursquare example here http://github.com/kylefowler/foursquare
Like all of my posts
Please use plain text.
Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Carrier: Wind Mobile

Re: Facebook API connection to Cascades/Native Development

[ Edited ]

Have to say, what I'd really like to see is an SDK from Facebook for BB10 the way they have a couple for iOS and Android...

 

Makes it a bit confusing how I should be configuring my app on their side.

 

I tried bb-cascades-oauth and adapting one of your samples, Kyle, but when I initiate the login sequence, it switches to the web browser and instead of a login page, I get my app name as a title and then a line with two buttons at the right -- "Cancel" and "Install". Neither do anything. I then have to close the browser and switch back to my app.

 

Does this sound like I've misconfigured something in the settings on Facebook?

 

I noticed that in the WebWorks example, it has to redirect to some external webpage first (a simple PHP script to send the right thing back to the app). That doesn't seem to be required in any of Kunal or Kyle's samples... Or am I missing something?

 

Maybe what's screwing things up is that I've got the app set as "Mobile Web". Should I try "Native Android App"?

 

Thanks.

Please use plain text.
Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Carrier: Wind Mobile

Re: Facebook API connection to Cascades/Native Development

[ Edited ]

Well, then. I suggest if anyone else ever reads this and has a problem like mine, they double-check the facebook URL. I made a typo and missed an 's', thus was connecting to http, not https. (The URL I defined above that was fine. :smileyindifferent: )

 

Now I have a new problem. I'm using bb-cascades-oauth, and I'm also using the redirect_uri from Kunal's example. I get the "Success" page, but don't see the access token appended to the URL, and bb-cascades-oauth doesn't give me an "onAuthorizationReceived" signal.

 

When I manually enter the dialog/oauth URL into the browser, the login_success.html URL I'm redirected to does have the access token.

 

Any obvious things to check before I start adding debug code everywhere (including inside the library)? The missing access token seems odd.

 

void facebook::login()
{
	KQOAuthParameters params;

	connect(_manager, SIGNAL(authorizationReceived(QString, QString)), this,
		SLOT(onAuthorizationReceived(QString, QString)));

        params.insert("redirect_uri", "https://www.facebook.com/connect/login_success.html");
	params.insert("response_type", "token");
	params.insert("scope", "...desired scope...");
	_manager->getOauth2UserAuthorization(QUrl("https://m.facebook.com/dialog/oauth"), _id, params);
}

 

My debug log shows this as the initial request URL:

https://m.facebook.com/dialog/oauth?client_id=<client_id>&response_type=token&redirect_uri=http://fb.elmr.ca/redirect.php&redirect_uri=https://www.facebook.com/connect/login_success.html&resp...<desired_scope>

 

If I paste that into my browser, I get:

https://www.facebook.com/connect/login_success.html#access_token=<access_token>

 

Please use plain text.
Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Carrier: Wind Mobile

Re: Facebook API connection to Cascades/Native Development

The redirect URL is fine now, so I just need to figure out why my app isn't getting notified by KQOAuth. I've been linking it as a shared library. Maybe it's time to link it in statically to make debugging a bit easier.

Please use plain text.
Developer
kylefowler
Posts: 525
Registered: ‎05-17-2009
My Carrier: ATT

Re: Facebook API connection to Cascades/Native Development

To get the library to handle the authorization, dont pass the redirect_uri as a parameter. The library sets up a local tcp server and passes its own localhost url with a port so that it gets the callback from the browser. I also think theres a flag you need to set when setting up the kqoauthmanager. I think its something like setHandlerUserAuthentication(true).

The other option, is to pull the latest bb-cascades-oauth library and there is another method that lets you just get the url that would be used for oauth2 and then pass that url to a webview and parse the token from the return url yourself. That way you could stay within your app and not go to the browser
Like all of my posts
Please use plain text.