iOS Facebook sdk v4.5.0。如何与帖子分享文字信息?

问题描述:

我必须在应用程序中使用v3.x中的Facebook SDK替换为v4.x。 当使用旧的SDK和下面的代码:iOS Facebook sdk v4.5.0。如何与帖子分享文字信息?

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) { 
          . . . . 
         }]; 

字符串变量味精通过文本时,帖子被共享消息:

enter image description here

在Facebook的SDK 4.x中有一个专门的对话这些任务没有任何领域或功能。我用下面的代码(即使OG: - 参数数量 - 甚至有OG:消息我已经尝试过),但我的帖子出现了无消息:

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

此消息可以传递给墙上只有从系统的Facebook对话ShareDialog,但用户必须手动输入消息:

enter image description here

所以我有两个问题:

1)即使没有这个FBSDKShareDialog,我可以分享我的文章吗?可能吗?

2)如果first == false - 如何通过消息以编程方式通过对话框发布?

在此先感谢!

+0

相关:http://*.com/questions/29854282/uiactivityviewcontroller-for-facebook-not-showing-default-text – AlexZd

下面的代码添加到您的应用程序:

FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init]; 
[action setString:message forKey: @"message"]; // This is the key point!