gpt4 book ai didi

ios - 使用 Facebook iOS SDK 3.x 将视频上传到 Facebook

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:18 24 4
gpt4 key购买 nike

我找到了很多使用 facebook SDK 上传视频的解决方案,但没有一个有效(包括来自 facebook 开发者博客的信息)。这是我用来上传视频的代码。 “out_composed.mov”已成功创建,因为我可以将该视频保存在图库中或通过电子邮件发送。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString* composedOutputPath = [documentsDirectoryPath stringByAppendingPathComponent:@"out_composed.mov"];
NSData *videoData = [NSData dataWithContentsOfFile:composedOutputPath];

NSMutableDictionary<FBGraphObject>* params = [FBGraphObject graphObject];
[params setDictionary:[NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"My awesome video", @"title", nil]];

if (!appDelegate.session.isOpen)
{
[FBSession openActiveSessionWithPermissions:[NSArray arrayWithObjects:@"offline_access", @"publish_stream",@"user_videos",@"video_upload",nil] allowLoginUI:true completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
FBRequest* uploadVideoRequest = [FBRequest requestForPostWithGraphPath:@"/me/videos" graphObject:params];
[uploadVideoRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
// The server returns "353 missing video file" here.
if(error != nil) NSLog(@"%@",[error description]);
else NSLog(@"Error: %@", error);
}];
}];
appDelegate.session = [FBSession activeSession];
} else
{
FBRequest* uploadVideoRequest = [FBRequest requestForPostWithGraphPath:@"/me/videos" graphObject:params];
[uploadVideoRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if(error != nil) NSLog(@"%@",[error description]);
else NSLog(@"Error: %@", error);
}];
}

我得到的错误是:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1fdc94a0 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 353;
message = "(#353) Missing video file";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}

我该如何解决这个问题?非常感谢!

平子

最佳答案

以下使用 3.0.8 SDK 对我有用(使用 -requestWithGraphPath:... 而不是 -requestForPostWithGraphPath:...):

NSDictionary *parameters = [NSDictionary dictionaryWithObject:videoData forKey:@"sample.mov"];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos" parameters:parameters HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(@"result: %@, error: %@", result, error);
}];

不过似乎缺少一种显示上传进度的方法。

关于ios - 使用 Facebook iOS SDK 3.x 将视频上传到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12110922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com