Reputation: 4728
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
thank you very much for your time reading this :)
Upvotes: 1
Views: 771
Reputation: 5523
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