Tag Friends in Facebook Photo Upload

后端 未结 1 1302
盖世英雄少女心
盖世英雄少女心 2021-02-04 19:31

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 us

1条回答
  •  误落风尘
    2021-02-04 20:29

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

    0 讨论(0)
提交回复
热议问题