EJV
EJV

Reputation: 1009

Feed Dialog not working on iOS SDK 3.0 beta (API error code 110)

I am updating my app to use the new Facebook SDK for iOS (3.0). However, I have run across an issue trying to use the feed dialog. I followed the instructions on Facebook's developer website regarding how to use the feed dialog with the new SDK, but I am getting this error when I show the dialog:

API Error Code: 110
API Error Description: Invalid user id
Error Message: Missing user cookie (to validate session user)

Here is my code:

Facebook *facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];

facebook.accessToken = FBSession.activeSession.accessToken;
facebook.expirationDate = FBSession.activeSession.expirationDate;

NSMutableDictionary *feedParams = [[NSMutableDictionary alloc] init];

[feedParams setObject:self.video.alternateLink.href
               forKey:@"link"];
// link title = video title
[feedParams setObject:self.video.title.stringValue
               forKey:@"name"];
// link picture = video thumbnail
[feedParams setObject:self.video.mediaGroup.highQualityThumbnail.URLString
               forKey:@"picture"];

NSDictionary *privacyDict = [NSDictionary dictionaryWithObjectsAndKeys:@"CUSTOM", @"value", @"SELF", @"friends", nil];
SBJSON *jsonWriter = [[SBJSON alloc] init];

[feedParams setObject:[jsonWriter stringWithObject:privacyDict error:NULL]
               forKey:@"privacy"];

[jsonWriter release];

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

[feedParams release];

self.facebook = facebook;
[facebook release];

It seems like an authentication problem, but I am passing a valid access token to the Facebook object, so I'm not sure what the problem is. If anybody could help me, that would be great. Thanks.

Upvotes: 3

Views: 2703

Answers (1)

Jason Clark
Jason Clark

Reputation: 1343

You may use FBSession.activeSession when integrating with the legacy Facebook class, as you have shown. One possible gotcha when you use activeSession, rather than directly instantiating a session object, is that it may not be open. Here is a simple sample that shows the form for integrating the Facebook class with active session:

if (FBSession.activeSession.isOpen) {
    // Create a Facebook instance
    Facebook *facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID
                                             andDelegate:nil]; // commonly self

    // Set the session information for the Facebook instance
    facebook.accessToken = FBSession.activeSession.accessToken;
    facebook.expirationDate = FBSession.activeSession.expirationDate;

    // Put together the dialog parameters
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"I'm using the the Facebook SDK for iOS", @"name",
                                   @"Facebook for iOS", @"caption",
                                   @"Check out the Facebook SDK for iOS!", @"description",
                                   @"https://developers.facebook.com/ios", @"link",
                                   @"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", @"picture",
                                   nil];

    // Invoke the dialog
    [facebook dialog:@"feed" andParams:params andDelegate:nil];

    [facebook release];
}

If the active session is not open, then you would get a failure along the lines of what you are seeing. A call along the lines of the following, somewhere earlier in your logic remedy this:

[FBSession openActiveSessionWithAllowLoginUI:YES];

Hope this helps!

Upvotes: 2

Related Questions