首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用iOS6社交框架将视频上传到Facebook

使用iOS6社交框架将视频上传到Facebook
EN

Stack Overflow用户
提问于 2012-10-04 07:16:41
回答 2查看 2.8K关注 0票数 4

我想向facebook发布一个视频文件。在此之前,我使用了Facebook iOS SDK3.0,它可以工作。然而,对于iOS6社会框架来说,存在问题。

代码语言:javascript
复制
 __block ACAccount * facebookAccount;
    ACAccountStore* accountStore = [[ACAccountStore alloc] init];
    NSDictionary *options = @{
    ACFacebookAppIdKey: @"MY APP ID",
    ACFacebookPermissionsKey: @[@"publish_actions", ], 
    @"ACFacebookAudienceKey": ACFacebookAudienceFriends
    };
    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    [accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {

        if (granted) {
            NSArray *accounts = [accountStore
                                 accountsWithAccountType:facebookAccountType];
            facebookAccount = [accounts lastObject];



            NSLog(@"access to facebook account ok %@", facebookAccount.username);

            NSData *videoData = [NSData dataWithContentsOfFile:[self videoFileFullPath]];
            NSLog(@"video size = %d", [videoData length]);
            NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                     videoData, @"video.mov",
                                    @"video/quicktime", @"contentType" ,
                                    @"Video title", @"title",
                                    @"Video description", @"description",nil];

            NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                                         requestMethod:SLRequestMethodPOST
                                                                                   URL:requestURL
                                                                            parameters:params];
            request.account = facebookAccount;
            [request performRequestWithHandler:^(NSData *data,                                                                  NSHTTPURLResponse *response,NSError * error){
                NSLog(@"response = %@", response);
                NSLog(@"error = %@", [error localizedDescription]);

            }];


        } else {
            NSLog(@"access to facebook is not granted");
            // extra handling here if necesary

        }

    }];

由于“NSInvalidArgumentException”异常终止应用程序,原因:'-NSConcreteData _fastCharacterContents:未识别的选择器发送到实例0x2097ead0‘

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-09 04:33:59

下面是我的研究:首先,视频数据不能成为参数列表的一部分,因为它将使SLRequest无效,这就是您正在经历的崩溃。

视频数据必须放在请求的多个部分中。

现在,需要将参数与多部分数据相关联,这是一个棘手的部分。因此,有必要使用source属性来创建该链接。

源需要字符串格式的URL,在参数中设置URL,并在多部分请求中的文件名字段中设置相同的值。

这样就行了。

代码语言:javascript
复制
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];

NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:videoPath];

NSString *status = @"One step closer.";
NSDictionary *params = @{@"title":status, @"description":status};

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodPOST 
                                                  URL:url 
                                           parameters:params];

[request addMultipartData:videoData
                 withName:@"source"
                     type:@"video/quicktime" 
                 filename:[videoPathURL absoluteString]];
票数 5
EN

Stack Overflow用户

发布于 2012-10-05 22:52:51

我也在处理同样的问题。我认为您的错误来自ARC,NSData *videoData在从performRequestWithHandler返回之前被删除。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12722091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档