5

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}
sujith1406
  • 2,822
  • 6
  • 40
  • 60

2 Answers2

3

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

  • the following link here clearly says that user generated photos should not be taken from the object. It should be set on the action... http://designerhubinc.blogspot.com/2012/06/user-generated-photos-in-open-graph.html – fatuhoku May 07 '15 at 16:23
  • This option only works when using FBSDKShareAPI as opposed to the Dialog. – fatuhoku May 07 '15 at 16:46
0

2: fatuhoku - thank for your comment. You are right - i'm using FBSDKShareAPI. If i create photo with userGenerated set to YES it is attached like photo. The photo is placed in my album (which is automatically created) with the name of my app and the post type is 'photo'. If i use userGenerated set to NO the photo is placed in internal FB stage, the post is type 'link' but i can extract photo from the post property 'picture' and with some trick by changing two parameters in picture URL w=130 and h=130 get necessary size of my photo. All this i do with API not with Dialogs.