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

Web and WebWorks Development

Reply
Regular Contributor
Posts: 86
Registered: ‎10-27-2010
My Device: Passport SQW100-1
My Carrier: Meteor

Re: OAuth: Twitter, Facebook & Foursquare Samples!

[ Edited ]

Still doesn't work.

I copied the FB part from app.js to fb.js
I replaced bfb_bootstrap.js complete and changed the BBM ID.


Get this error:


set click handlers fb.js:2
TypeError: 'undefined' is not an object (evaluating 'currentURL.indexOf'): 33

Line 33 in fb.js is:

var inCallback = currentURL.indexOf(callbackURL);

 

I tried putting the : facebookOptions = in function startOAuth() {

but that doesn't work either

 

I tried putting in:

 

var redirectUri = "http://myserver.com/fbouth.php";

and replace with: var inCallback = currentURL.indexOf(redirectUri);

 

But it wil give the same error, can it be that blackberry deleted indexof ?

I tried with: var inCallback = facebookOptions.redirectUri;

 

And i disabled: if (inCallback == 0) {  }

 

Now i get: TypeError: 'undefined' is not an object (evaluating 'code.split')

 

This means that there are more errors in the script.

 

Based on code.split and undefined it means that:  var code = childWindow.window.location.search;  does not work either.

 

I do get the blue page with close button (my app is dark theme so no blue by default)

So i tried to replace childwindow.window to only window.

 

Than i get:

 

GET https://graph.facebook.com/oauth/access_token?client_id=201*********&red…m/fbouth.php&client_secret=...

 

 

 

And i get the error: Error getting access_token;

 

 

So i tried to go direct to: onclick="startOAuth();"

 

I added a few extra console.log's to see what is going on, and this is the result.

 

console.log(url);
https://www.facebook.com/dialog/oauth?client_id=20123*****&redirect_ur…ope=email,read_friendlists,us... fb.js:31

 

console.log(currentURL);
local:///check.html fb.js:37

 

console.log(callbackURL);
http://myserver.com/fbouth.php fb.js:39

 

console.log(inCallback);
-1

 

 Small update, when i change: window.location.href; back to childWindow.window.location.href;

 

 

I get: TypeError: 'null' is not an object (evaluating 'childWindow.window')

 

I hope my findings are useful

 

 

BlackBerry Development Advisor
Posts: 634
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: OAuth: Twitter, Facebook & Foursquare Samples!

Hello,

 

I just used this sample last week without any issues, so I'm mostly confident the sample code works :smileyhappy:

 

As far as I remember, the only thing that might cause the issue when trying to access the childWindow object is if web security is enabeld, you may not be granted access to it.

 

In your config.xml have you disabled web security?

 

 

 

Also, if you compile and run the sample does it work, or is this error just in your application?

 

<access uri="*" subdomains="true" />
<preference name="websecurity" value="disable" />

 

Don't forget to add the plugins as well

 

com.blackberry.app
com.blackberry.ui.toast

 

New Member
Posts: 1
Registered: ‎12-13-2013
My Device: BlackBerry 10
My Carrier: BlackBerry

Re: OAuth: Twitter, Facebook & Foursquare Samples!

Hello to all!!!!!
A news for blackberry users, that now new action game Angry birds go! download free for iOS, Android, Windows Phone 8, and Blackberry 10 devices....
New Developer
Posts: 4
Registered: ‎03-17-2012
My Device: BlackBerry Z10
My Carrier: Airtel Uganda

Re: OAuth: Twitter, Facebook & Foursquare Samples!

Is it possible to update the Foursquare Sample to Webworks 2.0? 

 

Thanks

BlackBerry Development Advisor
Posts: 634
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: OAuth: Twitter, Facebook & Foursquare Samples!

Actually the best way to authenticate with Foursquare is to use the 'cards' method now.

 

There's a full sample (WebWorks 2 compatible) at https://github.com/blackberry/BB10-WebWorks-Samples/tree/WebWorks-2.0/Foursquare-Cards

New Member
Posts: 1
Registered: ‎08-13-2014
My Device: z10
My Carrier: Wind

Re: OAuth: Twitter, Facebook & Foursquare Samples!

Hello, thanks a lof for the example.  I just gave this a go;  Though of course the first thing you'll run into is the example uses a redirectUrl of another server ... for many phonegap applications this won't be possible (as of course there is no server).

That is OK there is a solution, that is utilizing a redirectUrl of:
https://www.facebook.com/connect/login_success.html

And requesting an access token directly (this is actually safer as well, you should store your app secret in the JS code ... the method used in the example, of requesting a CODE and than an access token is more suitable on a server).

It took a little bit of hacking but I got it working, I'll upload the code somewhere as I'm sure it'll be useful to others. But a question; I noticed no mater what domain I attempted to white list (i.e. https://www.facebook.com/connect) including sub domains it wouldn't work ... the problematic code is generally (from the example, slightly modified):

loginWindow = window.open(FB_LOGIN_URL ...
   
   window.int = self.setInterval(function() {
        var currentURL = loginWindow.window.location.href; <<<

 

As you are trying to access a frame from a different domain.


The only solution was to disable web-security all together, after which it finally worked ! I'm just curious, is there any way around this ?


Second question:

The above is all a little pain, most platforms handle the 'loadstart / loadstop / exit' handlers on windows.open, which makes the code a little cleaner and it would work on all phonegap platforms, will this be supported in web works one day ?

Thanks a lot !