5

I'd like to be able to tag existing friends using the graph api:

Here's the code I have at the moment. The photo is being uploaded, but the photo isn't tagging the user specified in the 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];

Is the message_tags attribute not the correct attribute to use?

Thanks!

EDIT From what I see here (https://developers.facebook.com/docs/reference/api/photo/#tags), it looks like I need to make three calls in total:

  1. Post the Photo with the code I already have
  2. Ask Facebook to give me the ID of this photo (which i can probably get from the FBRequestDelegate)
  3. Tag People after posting.
ArtSabintsev
  • 5,170
  • 10
  • 41
  • 71

1 Answers1

5

ok, figured it out.

Here's how you do it.

First, you upload the image.

        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];

Next, upon successful upload, the - (void)request:(FBRequest *)request didLoad:(id)result method will return a dictionary result with 1 key id. That ID is the photoID of the photo you just uploaded, which you save into a string:

NSString *photoID = [NSString stringWithFormat:@"%@", [(NSDictionary*)result valueForKey:@"id"]];

Then make another GraphAPI request to tag your friends. In the code below I am tagging one specific friends, but to tag multiple friends use CSV string or array:

[self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/tags/%@?access_token=%@", photoID, @"1381470076", self.socialIntegration.facebook.accessToken]
                                                    andParams:nil 
                                                andHttpMethod:@"POST" andDelegate:self];
ArtSabintsev
  • 5,170
  • 10
  • 41
  • 71
  • Can you please give an example of using this method to tag multiple friends? I've tried using a string with the IDs separated my commas (which is the standard for other requests), but that doesn't work here. Nor does passing an NSArray object in the graph request (I didn't really expect that to work though). I'd really appreciate it if you could just amend your answer with a quick answer to this. – Kiran Panesar Jun 08 '12 at 20:19
  • You do it JSON-style in your NSString `/photoID/tags?tags=[{"id":"1234"}, {"id":"12345"}]` – ArtSabintsev Jun 09 '12 at 21:09
  • +1 for the comment added for the multiple tagging "/photoID/tags?tags=[{"id":"1234"}, {"id":"12345"}]" – ashokdy Nov 06 '14 at 08:34