2015-09-06 52 views
1

我必須在應用程序中使用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://stackoverflow.com/questions/29854282/uiactivityviewcontroller-for-facebook-not-showing-default-text – AlexZd

回答

2

下面的代碼添加到您的應用程序:

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