Facebook iOS SDK: Cannot specify an album using the FBRequestForUploadPhoto request:

I have a local photo in the application for the iPhone, and I want to upload it to a special album on Facebook dedicated to my application.

Problem: My app’s name ends with the word β€œPhotos,” so the default Facebook album APP_NAME Photos Photos is obviously a problem.

Purpose:. I want to create a new album, save its identifier in NSUserDefaults and (after some checking at runtime) use it for all future photos downloaded from the application. p>

Where I am: I can create a new album through Open Graph, using my name and description, and I can get its identifier. I can also upload photos quite easily. However, I cannot figure out how to indicate where the uploaded photo ends!

Code: Here, my photo upload code with some comments is commented. I guess this is my problem since creating albums, etc. works great.

 - (void)postPhotosToFacebook:(NSArray *)photos withAlbumID:(NSString *)albumID { // Just testing with one image for now; I'll get in to multiple later.. UIImage *image = [photos lastObject]; FBRequest *imageUploadRequest = [FBRequest requestForUploadPhoto:image]; // CALL OUT: I'm guessing my problem is here - but I just don't know! [[imageUploadRequest parameters] setValue:albumID forKey:@"album"]; DebugLog(@"imageUploadRequest parameters: %@",[imageUploadRequest parameters]); // Results of DebugLog: // imageUploadRequest parameters: { // album = 10151057144449632; // picture = "<UIImage: 0xc6b6920>"; // } // The album data returns correctly using FB Graph API explorer tool, // so I know it a legit album. // https://developers.facebook.com/tools/explorer FBRequestConnection *connection = [[FBRequestConnection alloc] init]; [connection addRequest:imageUploadRequest completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { DebugLog(@"Photo uploaded successfuly! %@",result); // Results of DebugLog: // // Photo uploaded successfuly! { // id = 10151057147399632; // "post_id" = "511304631_10151057094374632"; // } // Again, the photo at that ID shows up correctly, etc - // BUT it in the wrong album! It shows up in the default app album. } else { DebugLog(@"Photo uploaded failed :( %@",error.userInfo); } }]; [connection start]; } 

Guess: I guess my problem is how I assign the album ID parameter to the image request .. but I have no idea.

You can see this URL to make this possible.

+6
source share
1 answer

Ahh SWEET. I thought this was one of the good old-fashioned, right craftsmen.

Given that there is no real instruction on how to apply the "album" value to FBRequest, I hesitate to call it a mistake, but in any case I need another method - in this case, just create a general Open Graph HTTP request and fill in all the information about image.

There is no real flaw in this approach; except that you cannot use the requestForUploadPhoto: method convenient.

Here is my implementation of the correct method (the remote code is commented out):

 - (void)postPhotosToFacebook:(NSArray *)photos withAlbumID:(NSString *)albumID { UIImage *image = [photos lastObject]; // FBRequest *imageUploadRequest = [FBRequest requestForUploadPhoto:image]; // // [[imageUploadRequest parameters] setValue:albumID // forKey:@"album"]; // // DebugLog(@"imageUploadRequest parameters: %@",[imageUploadRequest parameters]); NSString *graphPath = [NSString stringWithFormat:@"%@/photos",albumID]; DebugLog(@"graphPath = %@",graphPath); NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys: image,@"picture", nil]; FBRequest *request = [FBRequest requestWithGraphPath:graphPath parameters:parameters HTTPMethod:@"POST"]; FBRequestConnection *connection = [[FBRequestConnection alloc] init]; [connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { DebugLog(@"Photo uploaded successfuly! %@",result); } else { DebugLog(@"Photo uploaded failed :( %@",error.userInfo); } }]; [connection start]; } 
+6
source

Source: https://habr.com/ru/post/925735/


All Articles