Getting "Unsupported FBSDKGraphRequest" when posting a tagged photo

I'm trying to use FBSDKGraphRequest to upload a photo with a caption and tagged friends, but I'm really struggling to get the tags to work. This is what I got:

NSDictionary *parameters = @{
                             @"caption" : message,
                             @"picture" : UIImagePNGRepresentation(image),
                             @"tags"    : @[@{@"tag_uid": @902893713061742, @"x":@0.0, @"y":@0.0},
                                            @{@"tag_uid": @902486513129784, @"x":@10.0, @"y":@10.0}],
                             };

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:parameters tokenString:token.tokenString version:@"v2.3" HTTPMethod:@"POST"];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if(error)
        NSLog(@"%@", error);
    else
        NSLog(@"Success");
}];
[connection start];

      

But every time I try to run it this error comes up:

FBSDKLog: Unsupported FBSDKGraphRequest attachment :(
        {
         "tag_uid" = 902893713061742;
        x = 0; y = 0,
    },
        {
         "tag_uid" = 902486513129784;
        x = 10;
        y = 10;
    }
), skipping.

I have already tried several different ways to attach "tags" information, but none of them did the job. Does anyone know the correct way to do this? Is it possible? https://developers.facebook.com/docs/graph-api/reference/user/photos/ made me think like this.

EDIT: Tried posting without tags and then updating the post id with them, but still had no time :(

+3


source to share


3 answers


You cannot upload a photo with a caption and tagged friends using the same FBSDKGraphRequest. You must call different methods for different tasks, as shown below:

For post type header and tags:

if ([FBSDKAccessToken currentAccessToken]){
 NSDictionary *params = @{
                        @"message": @"This is a test message",
                       };
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        if (error)
         NSLog(@"error:%@", error);
        else{
            UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Text Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
            [av show];
            }
 }];
}

      



To post a photo:

if ([FBSDKAccessToken currentAccessToken]){
NSDictionary *params = @{@"sourceImage":UIImagePNGRepresentation(pickedImage)};
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if (!error) {
        UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Image Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
        [av show];
    } else {
        NSLog(@"Graph API Error: %@", [error description]);
    }
  }];
}

      

Hope it can help you ... :)

+3


source


You can upload a photo with the caption, you just need to change the key "signature" to "message"



if FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions") {
     let params: [NSObject : AnyObject] = ["message": "Caption", "sourceImage" : UIImagePNGRepresentation(image)]
     FBSDKGraphRequest(graphPath: "me/photos", parameters: params, HTTPMethod: "POST").startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
            // Handle result
     })
}

      

+1


source


Here's the basic code to run:

if (![FBSDKAccessToken currentAccessToken]) {
            [self alertWithMessage:@"Log into FB and request publish_actions" title:@"Upload Failed"];
            return;
        }
NSDictionary *params = @{@"source":UIImagePNGRepresentation([UIImage imageNamed:@"snoopy.png"])};

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
            if (!error) {
                [self alertWithMessage:[NSString stringWithFormat:@"Result: %@", result] title:@"Post Photo Success!"];
            } else {
                NSLog(@"Graph API Error: %@", [error description]);
            }
        }];

      

This is guaranteed to work as I tested it myself. Remember to check if your access token has publish_actions permission, as this may also affect whether you may or may not upload photos of people.

0


source







All Articles