Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing fb image and message content within the app not working using FBSDKShareDialog

I am using the following code to share a picture and some message on the fb timeline using FBSDK open graph object and FBSDK open graph content.however the following code does nothing,no dialog is presented nor does it post anything to the timeline.am i missing anything in this code or does this code not work in the simulator?

- (IBAction)shareButtonPressed:(id)sender {
    NSString *contentDesc=@"abcdcccdcc";
    NSString *title=[NSString stringWithFormat:@"%@ \n asd %@, asd %@",self.nameLabel.text,_fromDate.text,_toDate.text];

    FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
    photo.image = _profilePic.image;
    photo.userGenerated = YES;

    // Create an object
    NSDictionary *properties = @{
                                @"og:type": @"memories.memory",
                                 @"og:title":title ,
                                 @"og:description":contentDesc

                                 };
    FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject  objectWithProperties:properties];

    // Create an action
    FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
    action.actionType = @"memories.view";
    [action setObject:object forKey:@"memories.memory"];

    // Add the photo to the action
    [action setPhoto:photo forKey:@"image"];

    // Create the content
    FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
    content.action = action;
    content.previewPropertyName = @"memories.memory";

    [FBSDKShareDialog showFromViewController:self
                                 withContent:content
                                    delegate:nil];   
}

in the delegate method

-(void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{


    NSLog(@"%@",error);
}

the error log is printed as follows

Error Domain=com.facebook.sdk.share Code=2 "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)" UserInfo=0x7faec97bb660 {com.facebook.sdk:FBSDKErrorArgumentValueKey=<FBSDKShareOpenGraphContent: 0x7faecbc16740>, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Feed share dialogs support FBSDKShareLinkContent., com.facebook.sdk:FBSDKErrorArgumentNameKey=shareContent}
like image 447
sujith1406 Avatar asked Oct 20 '22 13:10

sujith1406


1 Answers

change [action setPhoto:photo forKey:@"image"]; to [object setPhoto:photo forKey:@"og:image"];

like image 178
Alexey Lobanov Avatar answered Oct 27 '22 22:10

Alexey Lobanov