1

I have to replace using Facebook SDK from v3.x to v4.x in my application. When it used old sdk with next code:

NSString *msg = [NSString stringWithFormat:@"%@\n%@\n%@", petition.petition_name, petition.recipient, petition.content];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        msg, @"message",
                        petition.uri ? petition.uri : [NSURL URLWithString:SITE], @"link",
                        nil
                        ];

NSLog(@"%@\n%@", msg, params);

[FBRequestConnection startWithGraphPath:@"me/feed"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                          .  .  .  .  
                      }];

string variable msg passed text message when post was sharing:

enter image description here

In Facebook SDK 4.x there is a special dialog that have no any field or function for such task. I use next code (even with og:- params - even there is og:message i've tried), but my post appeared with no message:

   FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
 photo.image = [self.pdata.imagesArr firstObject];
 // Optionally set user generated to YES only if this image was created by the user
 // You must get approval for this capability in your app's Open Graph configuration
 // photo.userGenerated = YES;

 NSString *urlStr = [NSString stringWithFormat:@"%@/api/images/%@?width=%f&height=%f&x=0&y=0&resize=1", K_BASE_URL, [[self.pdata.imagesArr firstObject] image_id], K_PETITION_IMAGE_WIDTH, K_PETITION_IMAGE_HEIGHT];

 // Create an object
 NSDictionary *properties = @{
 @"og:type": @"books.book",
 @"og:title": self.pdata.petition_name,
 @"og:description": self.pdata.content,
 @"og:image": urlStr,
 @"og:url": [NSURL URLWithString:self.pdata.uri],
 @"og:message": @"QQQQQQQWW",
 @"books:isbn": @"0-553-57340-3",
 };
 FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

 // Create an action
 FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
 action.actionType = @"books.reads";
 [action setObject:object forKey:@"books:book"];


 // Create the content
 FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
 content.action = action;
 content.previewPropertyName = @"books:book";

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

enter image description here

This message can be passed to the wall only from system facebook dialog ShareDialog, but user has to input message manually:

enter image description here

So i have two questions:

1) Can I share my post even without this FBSDKShareDialog? Is it possible?

2) If first == false - how can pass message to post through dialog programmatically?

Thanks in advance!

chatlanin
  • 5,257
  • 2
  • 16
  • 16
  • related: http://stackoverflow.com/questions/29854282/uiactivityviewcontroller-for-facebook-not-showing-default-text – AlexZd Sep 06 '15 at 13:19

1 Answers1

3

Add the code below to your app:

FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
[action setString:message forKey: @"message"];  // This is the key point!
Emmanuel
  • 13,935
  • 12
  • 50
  • 72