How to tag friends in startWithGraphPath Facebook iOS

风格不统一 提交于 2019-12-06 17:01:05

问题


I can't seem to get my posts to work using the Facebook SDK for iOS. I am using the "startWithGraphPath:parameters:HTTPMethod:completionHandler:" function. I can get the message, place, and picture working but I can't seem to tag friends. I have tried setting the NSDictionary key and object to

parameters[@"tags"] = self.friendsIDs; 

which is a string of comma separated Facebook User ID's (per the Facebook reference page: https://developers.facebook.com/docs/reference/api/user/#posts). However this always comes up:

com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            message = "(#100) param tags must be an array.";
            type = OAuthException;

So then I put them in an array and it still didn't work. In fact then I get a different error:

-[__NSArrayM length]: unrecognized selector sent to instance 0x1228abc0 2013-09-26 16:47:36.917 DrinkingGamePicker[27558:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x1228abc0sent to instance 0x1228abc0'

Anyone know how to format these parameters? I can't find any documentation or clear examples. Thanks in advance.

As a side note, does anyone know how to post from an app and tag people but not a place? I feel like every method means you have to at least tag a place first.

Thanks!


回答1:


From my experience, you can't tag friends with the post at the same time. However you can tag friends after the post is success. After posting, you should get the post id from the completionHandler block. Here is the code what i am using right now.

NSString *postId = //result from posting completionHandler;
NSString *path = [NSString stringWithFormat:@"%@/tags",postId];
NSMutableArray *tags = [NSMutableArray array];
for (NSString *friendId in self.tagFriends) {
    [tags addObject:[NSDictionary dictionaryWithObject:friendId forKey:@"tag_uid"]];
}

NSMutableDictionary *param = [NSMutableDictionary dictionary];
[param setObject:JSONStringWithObject(tags) forKey:@"tags"]; 
//JSONStringWithObject() is just a function develop by myself using NSJSONSerialization to wrap NSArray into JSON format NSString

[FBRequestConnection startWithGraphPath:path parameters:param HTTPMethod:@"POST"     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    //check error here 
}];


来源:https://stackoverflow.com/questions/19040562/how-to-tag-friends-in-startwithgraphpath-facebook-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!