使用iOS SDK在个人Facebook墙上发布并立即标记多个朋友



我正在尝试在墙上发布一条消息,并希望在这篇文章中一次标记多个用户。我尝试了FB帖子页面上的各种选项,但无法做到。我可能不是做对的。任何帮助都将受到赞赏,这就是我的做法...

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Test 2",@"message",
                               @"100004311843201,1039844409", @"to",
                               nil];
[self.appDelegate.facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

我也尝试过message_tags,但这似乎也不起作用。

您需要使用打开的图形来标记使用消息的人。me/feed图API端点不支持此。

提到标签https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/

行动标记:https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/

您可以查看最新的Facebook SDK包含的美味示例应用程序,以查看如何执行此操作。

用fbfriendpickerviewcontroller使用fb friendspickerviewcontroller和" plote id",使用fbplacepickervereviewcontroller使用fb friendpickerviewcontroller和" plote id"来标记您的朋友的" Facebook ID"。以下代码将帮助您。

NSString *apiPath = nil;
apiPath = @"me/feed";
if(![self.selectedPlaceID isEqualToString:@""]) {
    [params setObject:_selectedPlaceID forKey:@"place"];
}
NSString *tag  = nil;
if(mSelectedFriends != nil){
    for (NSDictionary *user in mSelectedFriends) {
        tag = [[NSString alloc] initWithFormat:@"%@",[user objectForKey:@"id"] ];
        [tags addObject:tag];
    }
    NSString *friendIdsSeparation=[tags componentsJoinedByString:@","];
    NSString *friendIds = [[NSString alloc] initWithFormat:@"[%@]",friendIdsSeparation ];
    [params setObject:friendIds forKey:@"tags"];
}
FBRequest *request = [[[FBRequest alloc] initWithSession:_fbSession graphPath:apiPath parameters:params HTTPMethod:@"POST"] autorelease];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    [SVProgressHUD dismiss];
    if (error) {
        NSLog(@"Error ===== %@",error.description);
        if (_delegate != nil) {
            [_delegate facebookConnectFail:error requestType:FBRequestTypePostOnWall];
        }else{
            NSLog(@"Error ===== %@",error.description);
        }

    }else{
        if (_delegate != nil) {
            [_delegate faceboookConnectSuccess:self requestType:FBRequestTypePostOnWall];
        }
    }

如果您遵循有关如何为iOS设置打开图的教程,则可以使用friendspickerController:

执行此类操作。
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
//Iterate over selected friends
if ([friendPickerController.selection count] > 0) {
    NSMutableArray *temp = [NSMutableArray new];
    for (id<FBGraphUser> user in self.friendPickerController.selection) {
        NSLog(@"Friend selected: %@", user.name);
        [temp addObject:[NSString stringWithFormat:@"%@", user.id]];
    }
    [action setTags:temp];
}

基本上,您可以在操作上的"标签"属性上设置朋友的ID数组

最新更新