我想分享到Facebook或使用Open Graph Stories创建故事。我跟着他们的例子,我可以分享照片,像这样的动作。
但是,我需要在帖子中提及页面。我正在读这个 https://developers.facebook.com/docs/sharing/opengraph/using-actions#mentions
它描述了如何提及。但我不知道如何在iOS中调用那个。我可以知道该怎么做吗?
// Construct an FBSDKSharePhoto
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:@"instruction1.jpg"];
// 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;
// Create an object
NSDictionary *properties = @{
@"og:type": @"books.book",
@"og:title": @"A Game of Thrones",
@"og:description": @"In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.",
@"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"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:@[photo] forKey:@"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"books:book";
[FBSDKShareDialog showFromViewController:[AppDelegate instance].window.rootViewController
withContent:content
delegate:nil];
编辑:我改变了这样的话。首先,我让用户使用Facebook登录按钮登录Facebook。在那之后,我触发了这个。我可以成功发布到Facebook,但我无法提及自己,或者我无法提及页面。它只显示页面ID或用户ID。我该怎么办?
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@"User ID is %@", [FBSDKAccessToken currentAccessToken].userID);
NSString *msg = [NSString stringWithFormat:@"This is a test message with page ID = @[455272221218150] and user ID = @[%@]",[FBSDKAccessToken currentAccessToken].userID];
NSDictionary *params = @{
@"message": msg, @"access_token": [FBSDKAccessToken currentAccessToken], @"book": @"http://www.example.com/book/09485736/"
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me/feed"
parameters:params
HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
}