Jef
Jef

Reputation: 4728

Tagging facebuddies to a posted photo IOS facebook sdk 3.0 possibly permissions issue

Im uploading and posting an image to a users Facebook from my (ios) code using the FacebookSDK3 and presenting a friendPickerController view, selecting an array of friends and trying to attach a tag to the pic.

This is my code for the actual tagging, it runs ok but then i get an error in the debugger, Error: HTTP status code: 200, and it was Error: HTTP status code: 400 when i applied a stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding to the graph path. It appears to be a permissions type error.. (this method is called after the pic is uploaded successfully, self.upLoadedPicID is NSString with the fbID for the post, and self.tagList is a NSMutableArray of objects (facebuddies to tag) passed back from the friendPickerController..

 -(void)tagFriends{

    if ([self.tagList count] > 0 && imageUploaded && [self.upLoadedPicID length]) {
    self.activityLabel.text = @"Tagging Photo";
    [self setSpindicatorOn:YES];

    NSMutableString *graphPath = [NSMutableString string];
    [graphPath appendString:self.upLoadedPicID];
    [graphPath appendString:[NSString stringWithFormat:@"/tags?tags=["]];


    // loopthru tag array..

    NSMutableString *iDs = [NSMutableString string];

    for (id<FBGraphUser> user in self.tagList) {

               if ([iDs length]) {
                [iDs appendString:@", "];
               }  //deliniate after first entry..

      NSString *entry = [NSString stringWithFormat:@"{\"tag_uid\":\"%@\"}", user.id];
      [iDs appendString:entry];
      }


    [graphPath appendString:iDs];[graphPath appendString:[NSString stringWithFormat:@"]&access_token=%@",[FBSession activeSession].accessToken]];
 //  NSLog(@"building graph path for tAgging %@", graphPath);
   //works fine
    FBRequestConnection *connection = [[FBRequestConnection alloc]init];
    FBRequest *request = [FBRequest requestForGraphPath:graphPath];


  // do i need URL encoding???

 //   NSString* escapedUrlString = [graphPath stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
  //  FBRequest *request = [FBRequest requestForGraphPath:escapedUrlString];

   // dont think so..

   [connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error){

//     if (error) {
//       NSLog(@"error tagging");
       [self setSpindicatorOn:NO];
//     }else{
//       NSLog(@"done tagging");
//       [self setSpindicatorOn:NO];}
//   
     [self showAlert:@"done Tagging" result:result error:error];


   } batchEntryName:nil];
    [connection start];
   // [request ]
  }

}

The fbSession is alloc'd in the appDelegate and passed into the fbViewcontrollers before theyre presented with this, so perhaps my issue is the permissions that i've used here? I cant find any documentation on alternate permission strings to use here..

self.fbLoginView = [[FBLoginView alloc]initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];

the other possibility is that I didnt set up my facebook end app with the right permissions, I can go in and edit that, but its only a text entry, not a drop down menu or anything intuitive like that, and every list I can find of GraphApi permissions makes no mention of tagging friends to photos, its unclear whether the 'publish stream' permission is enough in GraphApi although there is documentation that it was not enough in the deprecated REST API, there you needed a publish_stream_extended permission, but I cant see any corresponding permission in GraphAPI.

If any of you can tell me where Ive gone wrong I'll be eternally grateful, and I apologize if there is a duplicate question, I've looked and looked, because of the deprecated REST API and the different SDKs that facebook has issued over time its very difficult to see what has changed and what has not.

I guess the key questions if anyone knows are

  1. what are the permission settings to make in a facebook serverside app in order to have privilege to tag friends to a photo?
  2. what are the corresponding permissions to init into your facebook session object?
  3. Does Facebook not want you doing this anymore and is this why there is so little documentation?
  4. am I completely barking up the wrong tree here?

thank you very much for your time reading this :)

Upvotes: 1

Views: 771

Answers (1)

C Abernathy
C Abernathy

Reputation: 5523

  1. Ask for user_photos permissions so you can tag friends in a photo
  2. With the latest Facebook SDK v3.1 you need to split up your read/write permissions to take advantage of iOS6. Ask for user_photos permissions to begin with and ask for publish_actions permissions in context, when you're about to publish a photo.
  3. Docs can be found here explaining the permissions: https://developers.facebook.com/docs/reference/api/photo/

Hint: Whenever you're stuck, go to the Graph API Explorer and play with different permissions, input, etc. to get things write before you move on to code or just use it if you get stuck.

Upvotes: 1

Related Questions