我编写了如下代码,其中文件存在于资源中。它不为空。
我成功地添加了图像,但卡在了视频上。
-(void)uploadVideo {
NSLog(@"UPload Videio ");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error:&error];
if(data == nil && error!=nil) {
//Print error description
NSLog(@"error is %@", [error description]);
}
NSLog(@"data is %@", data);
NSDictionary *parameters = [NSDictionary dictionaryWithObject:data forKey:@"sample.mov"];
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:parameters
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// [FBRequestConnection setVideoMode:NO];
if(!error) {
NSLog(@"OK: %@", result);
} else
NSLog(@"Error: %@", error.localizedDescription);
}];
} else {
// We don't have an active session in this app, so lets open a new
// facebook session with the appropriate permissions!
// Firstly, construct a permission array.
// you can find more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
// In this example, we will just request a publish_stream which is required to publish status or photos.
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
nil];
//[self controlStatusUsable:NO];
// OPEN Session!
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:parameters
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// [FBRequestConnection setVideoMode:NO];
if(!error) {
NSLog(@"Result: %@", result);
} else
NSLog(@"ERROR: %@", error.localizedDescription);
}];
//[self promptUserWithAccountNameForUploadPhoto];
}
// [self controlStatusUsable:YES];
}];
}
}
作为回报,我收到错误消息
The operation couldn’t be completed. (com.facebook.sdk error 5.)
如何使用 facebook iOS SDK 将视频上传到 facebook?
谢谢