Facebook iOS SDK:无法使用 FBRequest 的 requestForUploadPhoto 指定相册: [英] Facebook iOS SDK: Cannot specify an album using FBRequest's requestForUploadPhoto:
问题描述
我的 iPhone 应用中有一张本地照片,我想将它上传到 Facebook 上专门用于我的应用的特定相册.
I have a local photo in my iPhone app, and I want to upload it to a specific album on Facebook dedicated to my app.
问题:我的应用名称以照片"一词结尾,因此默认的 Facebook 相册是 APP_NAME 照片照片
- 显然有问题.
Problem: My app name ends with the word 'Photos', so the default Facebook album is APP_NAME Photos Photos
- obviously a problem.
目标:我想创建一个新相册,将其 ID 存储在 NSUserDefaults
中,并且(在运行时进行一些验证后)将其用于以后上传的所有照片应用程序.
Goal: I want to create a new album, store its ID in NSUserDefaults
, and (after some validation at runtime) use it for all future photos being uploaded from the app.
我在哪里:我可以通过 Open Graph 制作新专辑,使用我想要的名称和描述,我可以检索它的 ID.我也可以很容易地上传照片.但是,我无法弄清楚如何指定上传的照片的最终位置!
Where I'm at: I can make the new album via Open Graph, using my desired name and description, and I can retrieve its ID. I can also upload photos easily enough. However, what I CANNOT figure out is how to specify where that uploaded photo ends up!
代码:这是我的照片上传代码,其中一些结果被注释.我假设这是我的问题所在,因为相册创建等工作正常.
Code: Here's my photo upload code with some results commented in. I'm assuming this is where my problem is, since album creation, etc, is working perfectly.
- (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's Graph API explorer tool,
// so I know it's 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's in the wrong album! It shows up in the default app album.
} else {
DebugLog(@"Photo uploaded failed :( %@",error.userInfo);
}
}];
[connection start];
}
猜测:我猜我的问题在于我如何将我的相册 ID 参数分配给图像请求......但我不知道.
Guesses: I'm guessing my problem is somewhere in how I'm assigning my album ID parameter to the image request.. but I have no clue.
您可以在 这个 URL 这应该是可能的..
You can see at this URL that this should be possible..
推荐答案
Ahh SWEET.我通过一些老式的、直接的修补来解决这个问题.
Ahh SWEET. I figured this one out with some good old-fashioned, straight-up tinkering.
鉴于没有关于如何将专辑"值应用于 FBRequest 的真正说明,我犹豫将其称为错误,但无论哪种方式,我都需要一种不同的方法 - 在这种情况下,只需创建一个通用的 Open GraphHTTP请求并填写所有图片信息.
Given that there is no real instruction on how to apply the 'album' value to an FBRequest, I hesitate to call it a bug, but either way I needed a different method - in this case, simply creating a generic Open Graph HTTP request and filling in all the image info.
这种方法没有真正的缺点;除了您不能使用 requestForUploadPhoto: 便捷方法.
There is no real downside to this approach; except that you can't use the requestForUploadPhoto: convenience method.
这里是我对正确方法的实现(删除的代码被注释掉了):
Here is my implementation of the correct method (removed 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];
}
这篇关于Facebook iOS SDK:无法使用 FBRequest 的 requestForUploadPhoto 指定相册:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!