我希望能够使用图形api标记现有朋友:
这是我目前的代码。正在上传照片,但照片未标记user_id中指定的用户:
UIImage *testImage = [UIImage imageNamed:@"sendingTo"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kFacebookFBConnectAppID, @"app_id",
testImage, @"source",
@"1381470076", @"message_tags",
@"TEST!", @"message", nil];
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:@"/me/photos?access_token=%@", self.socialIntegration.facebook.accessToken]
andParams:params
andHttpMethod:@"POST" andDelegate:self];
message_tags
属性不是正确的属性吗?
谢谢!
修改 从我在这里看到的(https://developers.facebook.com/docs/reference/api/photo/#tags),看起来我需要总共进行三次调用:
答案 0 :(得分:5)
这是你如何做到的。
首先,您上传图片。
UIImage *testImage = [UIImage imageNamed:@"sendingTo"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kFacebookFBConnectAppID, @"app_id",
testImage, @"source",
@"TEST!", @"message", nil];
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:@"/me/photos?access_token=%@", self.socialIntegration.facebook.accessToken]
andParams:params
andHttpMethod:@"POST" andDelegate:self];
接下来,成功上传后,- (void)request:(FBRequest *)request didLoad:(id)result
方法将返回包含1个密钥result
的字典id
。该ID是您刚上传的照片的photoID,您将其保存为字符串:
NSString *photoID = [NSString stringWithFormat:@"%@", [(NSDictionary*)result valueForKey:@"id"]];
然后再制作另一个GraphAPI请求以标记您的朋友。在下面的代码中,我正在标记一个特定的朋友,但要标记多个朋友使用CSV字符串或数组:
[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/tags/%@?access_token=%@", photoID, @"1381470076", self.socialIntegration.facebook.accessToken]
andParams:nil
andHttpMethod:@"POST" andDelegate:self];