作为用户在我的应用程序中执行某些操作的事件,我想代表他们将图像发布到 Facebook。假设用户已经在类 LoginVC 中授予了我 publish_actions 权限(一次权限用于将来无限发布)。然后在将来的某个时候,在 ActionVC 中,我想将照片发布到 Facebook。我怎么做?这是我需要实现的方法:
- (void)publishPhoto:(UIImage *)image
{
//what goes in here?
}
到目前为止,我一直在查看来自 Facebook 的样本。我最接近的是以下,但它似乎正在使用一个对话框。但我不希望用户“知道”照片正在发布。他们已经授予了许可,我希望在他们不知情的情况下发布。所以其他一些行动触发了发布的呼吁......
作为参考,Facebook 示例中的代码如下所示
- (void)publishPhoto:(UIImage *)image
{
BOOL canPresent = [FBDialogs canPresentShareDialogWithPhotos];
NSLog(@"canPresent: %d", canPresent);
FBPhotoParams *params = [[FBPhotoParams alloc] init];
params.photos = @[image];
BOOL isSuccessful = NO;
if (canPresent) {
FBAppCall *appCall = [FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
NSLog(@"Error: %@", error.description);
} else {
NSLog(@"Success!");
}
}];
isSuccessful = (appCall != nil);
}
if (!isSuccessful) {
[self performPublishAction:^{
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
connection.errorBehavior = FBRequestConnectionErrorBehaviorReconnectSession
| FBRequestConnectionErrorBehaviorAlertUser
| FBRequestConnectionErrorBehaviorRetry;
[connection addRequest:[FBRequest requestForUploadPhoto:image]
completionHandler:^(FBRequestConnection *innerConnection, id result, NSError *error) {
[self showAlert:@"Photo Post" result:result error:error];
if (FBSession.activeSession.isOpen) {
self.buttonPostPhoto.enabled = YES;
}
}];
[connection start];
self.buttonPostPhoto.enabled = NO;
}];
}
}
对不起,如果这个问题看起来太简单了,但我是 Facebook SDK 集成的新手