1

I am using facebook api to share facebook .i am using

[self.facebook dialog:@"feed" andParams:params andDelegate:self];

on button action .But first time the popupwindow is showing but immediately it is dismissing.There it is showing the error in console.The problem here it is It is opening two requests at a time.That too those requests are same.But second time it is opening fine(no problem and no errors).How to ignore this and open only one request at first time?.

Univer
  • 325
  • 2
  • 6
  • 18

1 Answers1

0

Are you authorizing the user just before showing the feed dialog? I helped out another fella who had the same issue a while back: Facebook iOS SDK - Strange Effects in Writing to Status

If that is the case, both authorization and showing the dialog will trigger a dialog to be displayed. You'll have to be sure to only do one at a time (authenticate > wait for success > show feed dialog).

EDIT: This is pretty much how I'm doing it:

MyClass.h

An instance variable where I save the object to share (if authorization is needed):

MyObject *_objectToShare;
...
@property (nonatomic, retain) MyObject *objectToShare; // @synthesized in MyClass.m

MyClass.m

Method used to share the object (via a NSNotification):

/**
 * Method invoked to share an object on Facebook.
 */
- (void)shareObject:(NSNotification *)note {

    // show dialog if authorized, otherwise authenticate first
    if ([_facebook isSessionValid]) {
        // Use Facebook share dialog
        NSMutableDictionary *params = [NSMutableDictionary dictionary]; // define key-value params to send to FB

        // show feed dialog
        [_facebook dialog:@"feed" andParams:params andDelegate:self];

        // Clear object to share (as it's been shared now)
        self.objectToShare = nil;
    }
    else {
        // authorize with defined permissions
        [_facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"publish_actions", nil]]; // the permissions you need (@see http://developers.facebook.com/docs/reference/api/permissions/)

        // save a reference to the track to share (after auth is done)
        self.objectToShare = channel;
    }

}

The object is shared when user has been authorized by Facebook:

/**
 * From FBSessionDelegate. Invoke method to share object if any is defined.
 */
- (void)fbDidLogin {
    // share queued object if it's defined
    if (self.objectToShare) {
        [self shareObject:nil]; // don't pass any notification
    }
}
Community
  • 1
  • 1
Kristofer Sommestad
  • 3,061
  • 27
  • 39
  • can u please tell me in the code.I need to write when i click on the button that need to post on wall? – Univer Dec 12 '11 at 09:21
  • what is kFACEBOOK_PERMISSIONS macro,where we need to define ? – Univer Dec 12 '11 at 10:01
  • do we need to write [_facebook authorize:permissions]; [_facebook dialog:@"feed" andParams:params andDelegate:self]; these methods inside the IBAction ? – Univer Dec 12 '11 at 10:08
  • kFACEBOOK_PERMISSIONS is an NSArray with the permissions you need for your FB integration, i.e. `[NSArray arrayWithObjects:@"publish_stream", @"publish_actions", nil]`. See the FB docs for more info: http://developers.facebook.com/docs/reference/api/permissions/ – Kristofer Sommestad Dec 12 '11 at 10:43
  • You could invoke `-shareObject:` from within your `IBAction` (if that's from where you want to show the dialog). – Kristofer Sommestad Dec 12 '11 at 10:45
  • but it is going to if condition means the session is valid. – Univer Dec 12 '11 at 11:05
  • The fallowing post is exactly i am getting .http://stackoverflow.com/questions/8002260/first-dialog-after-authenticating-fails-immediately-and-closes-dialog/8016055#comment9863824_8016055 – Univer Dec 12 '11 at 11:06