我正在尝试在我的墙上发帖并在其上标记多个朋友,到目前为止,我已设法在我的墙上张贴,现在只留下标记。我已经在堆栈Post on personal Facebook wall using ios sdk and tag multiple friends at once..?中查看了这个问题,并在https://developers.facebook.com/docs/opengraph/guides/tagging/检查了facebook中标记的说明,但仍不确定如何在iOS中实现此功能。这是我目前在我的墙上张贴的代码
-(void)shareAdOnFacebook:(NSString *) wallMessage UserId:(NSString *) userID
{
NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists", nil];
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Test miLineup!", @"message", @"Iphone Apps", @"name", nil];
NSLog(@"\nparams=%@\n", params);
NSLog(@"PERMISSIONS:%@",[[FBSession activeSession]permissions]);
if ([[FBSession activeSession]isOpen]) {
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
NSLog(@"Perform operation");
[self postOnWall:wallMessage UserId:userID];
}];
}else{
NSLog(@"Perform operation");
[self postOnWall:wallMessage UserId:userID];
}
}else{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
NSLog(@"Status is Open");
[self postOnWall:wallMessage UserId:userID];
}else{
NSLog(@"error");
}
}];
}
}
- (void)postOnWall:(NSString *) wallMessage UserId:(NSString *) userID
{
NSNumber *testMessageIndex=[[NSNumber alloc] init];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"testMessageIndex"]==nil)
{
testMessageIndex=[NSNumber numberWithInt:100];
}
else
{
testMessageIndex=[[NSUserDefaults standardUserDefaults] objectForKey:@"testMessageIndex"];
};
testMessageIndex=[NSNumber numberWithInt:[testMessageIndex intValue]+1];
[[NSUserDefaults standardUserDefaults] setObject:testMessageIndex forKey:@"testMessageIndex"];
[[NSUserDefaults standardUserDefaults] synchronize];
// create the connection object
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request for fbid's profile
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:@"me" result:result error:error];
};
NSString *messageString=wallMessage;
FBRequest *request= [FBRequest requestWithGraphPath:userID parameters:[NSDictionary dictionaryWithObject:messageString forKey:@"message"] HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
// FBSample logic
// Report any results. Invoked once for each request we make.
- (void)requestCompleted:(FBRequestConnection *)connection
forFbID:fbID
result:(id)result
error:(NSError *)error
{
NSLog(@"request completed");
// not the completion we were looking for...
if (self.requestConnection &&
connection != self.requestConnection)
{
NSLog(@" not the completion we are looking for");
return;
}
// clean this up, for posterity
self.requestConnection = nil;
if (error)
{
NSLog(@" error:%@",error);
}
else
{
NSLog(@" ok");
};
}
通过这个我可以发布在自己的墙上,我需要修改它以标记其他用户。
答案 0 :(得分:0)
请参阅此处的文档:https://developers.facebook.com/docs/graph-api/reference/user/feed/#pubfields
您已经使用“message”属性创建了一个字典,只需添加“tags”和“place”属性。
“tags”是逗号分隔的用户ID列表。
请注意,如果您还指定了“地点”,则只能标记用户。