3

I'm updating my app to use xCode 4, iOS5 and the latest Facebook SDK. All was working fine before.

Now, two strange things are happening and despite reviewing all the code and searching the forums, I can't see why.

See update below.

Logging in for first time

When the user has just logged in, if they either share the status or cancel the attempt to do so, a script is displayed as follows:

<script type="text/javascript"> window.location.href="fbconnect:\/\/ success#_=_";
</script>

All other functionality (e..g when its not the first time) seems to work fine.

I suspect this is something to do with call backs not firing, but I've double checked all the delegate setting etc. All the facebook delegate methods are in the appDelegate and then referred to from the view controller.

Has anyone else had this issue? Any pointers would be warmly welcomed. I haven't posted any code yet as I'm not sure which bit to focus on and I've used all the standard code from the facebook developer site.

Many thanks,

Chris.

UPDATE

Thanks to @Kristofer Sommestad and @Senior for their help. I had a number of issues.

Don't Authorise Twice

The feed dialog request also requests an authorisation, so don't request them both at the same time.

Updated SDK

The SDK was updated after I found my issues - so keep checking.

What I hadn't realised was that the required code to use the SDK code had changed, specifically the code to call the feed dialog. Check out https://developers.facebook.com/docs/reference/dialogs/feed/.

What Logout Means

Logging out just logs the user out of your App, not out of facebook.

Chris
  • 1,449
  • 1
  • 18
  • 39

3 Answers3

5

I also experienced the first issue, but solved it by making sure authentication wasn't triggered twice. Initially, I had done the following:

[_facebook authorize:permissions];
[_facebook dialog:@"feed" andParams:params andDelegate:self];

Not sure this is your problem, but I noticed that this messed things up as it actually triggered 2 authentication dialogs, where the second one ended up with the Javascript output you're also seeing. For some reason I had figured that the second one wouldn't trigger a dialog if authorize already had done so....

Instead, I made sure to authorize: first, but not trigger the dialog:andParams:andDelegate until the authorization was completed with -fbDidLogin (and saving the dialog data to share as an instance variable).

Haven't seen any issues with still being able to post messages, but maybe it's related to the first issue somehow (?).

Hope this helps you out too.

Kristofer Sommestad
  • 3,061
  • 27
  • 39
  • Thanks Kristofer and @Senior. There has been an update in the last couple of days, so I've downloaded that and at least one of the warnings has gone. I suspect I've also got the same problem with double auth as you but am just figuring out to see how to stop it. My sessiondelegate is the AppDelegate but the dialog is called from the viewcontroller. How about you? – Chris Nov 04 '11 at 11:01
  • Yeah, I had the same set up, but made sure that the `AppDelegate` displayed the dialog as well (through an `NSNotification` with the dialog data as payload). That way, I could save the dialog data as an instance variable in the `AppDelegate` and use it to show a dialog from `-fbDidLogin`. Or if already authenticated, just show it as soon as the `NSNotification` was received. – Kristofer Sommestad Nov 04 '11 at 11:29
  • You rightly identified the issue being a double authorisation. So now, I don't try to update the facebook status (the feed dialog) at the same time as requesting authorisation. So I either do it immediately if the user has already authorised the App or within fbDidLogin if not. I also had some other issues which I've documented in my updated question. So thanks for pointing me in the right direction. – Chris Nov 04 '11 at 13:47
  • No problem. Good luck! So... what about the bounty? :) – Kristofer Sommestad Nov 04 '11 at 14:29
  • I thought ticking your answer would do that, but obviously not. I've sent it you now. Thanks. – Chris Nov 04 '11 at 14:42
  • I am not sure how good this solution is. In my case the user is not presented with an in-app dialog, but is redirected to a web view. Also after the credentials are entered there is an extra step to press the login button. Can you provide the code that you used Kristofer? I assume that you do it differently than me. –  Jan 14 '12 at 03:32
  • Facebook's SSO (single-sign-on) solution will open a Safari web page if you don't have the FB app on your device (typically on the simulator), otherwise the FB app will be opened for the authentication. Can't say that I recall any second login step, but there is usually a 2nd screen where you'll have to authorize the app. – Kristofer Sommestad Jan 31 '12 at 10:25
  • Hi, sorry to say, but it doesn't work for me. I use sharekit and in the facebook dialog it shows the same problem Chris describs. I already looked for a sharkit update, but it seem that 0.2.1 is the latest version. When i change the source, so the authorize-Method is first beeing called, it justs switches to the Safari (because of SSO). And also at any time the i wants to post something, it just switches to safari, which is not a good behaviour. Anyone has any idea? – NicTesla Aug 22 '12 at 14:54
1

Okay, I just did a pull from the GitHub repository, and I'm not getting this error anymore. It is, however, calling (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error

Try updating to the latest version of the SDK and trying again.

Senior
  • 2,259
  • 1
  • 20
  • 31
1

This unwanted javascript-view bothers me too.
I just use the facebook feed dialog [facebook dialog: @"feed" andParams: myParameters andDelegate: ptrMyDialogDelegate];. Like shown at https://developers.facebook.com/docs/reference/dialogs/feed/. I do no other authorization anywhere else.
The Delegate is my AppModel-Class (not the AppDelegate). All methods of the FBDialogDelegate-Protocol are called correctly but after I close this annoying view.

I didn't use GIT. I downloaded the ZIP-File and copied all source files *.[h|m] from src/ directory (including src/JSON/ subdir) and the FBDialog.bundle (23 files in total) into my existing project.

Does it make any difference if I download the ZIP-File or clone the Facebook iOS SDK GIT-Repository?

To integrate the Facebook classes into my existing MyApp-project (means MyApp class tree like shown in Xcode Project Navigator) I do have to copy (e.g. drag'n drop or Xcode "Ad Files ...") the Facebook classes the same way, don't I?

noone
  • 155
  • 1
  • 2
  • 10
  • Please see my original posting as well: http://stackoverflow.com/questions/8236359/facebook-feed-dialog-returns-a-unhandled-javascript-including-post-id-that-crash – noone Nov 25 '11 at 07:23