繁体   English   中英

在使用SLRequest在Facebook上发布视频上传权限之前,如何获得阅读权限?

[英]how to get read permission before publishing permission for uploading video on Facebook using SLRequest?

我只是想将Facebook共享集成到我的应用程序中,我的应用程序的最终产品是一个视频,因此我想到的是与朋友上传和共享最终编辑,我正在将本机社交框架与ACAccount Framework结合使用,以使我的应用程序正常工作来自Facebook的似乎有些奇怪的逻辑,我需要在请求publish_stream许可之前先请求读取许可,并且它们不能紧随其后(在某处读取),我的问题是我应该在哪里以及如何在我的代码中实现此逻辑,这里我的代码

    ACAccountStore* accountStore = [[ACAccountStore alloc] init];
NSDictionary *options = @{
                          ACFacebookAppIdKey: @"My app ID",
                          ACFacebookPermissionsKey: @[@"user_birthday"],
                          ACFacebookAudienceKey: ACFacebookAudienceOnlyMe
                          };
ACAccountType *facebookAccountType = [accountStore
                                      accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {

    if (granted) {

        NSArray *accounts = [accountStore
                             accountsWithAccountType:facebookAccountType];
         ACAccount * facebookAccount = [accounts lastObject];



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

        NSData *videoData = [NSData dataWithContentsOfFile:[_fURL absoluteString]];
        NSLog(@"%@",[_fURL absoluteString]);
        NSLog(@"video size = %d", [videoData length]);
        NSDictionary *params = @{
                                 @"title": @"Me being silly",
                                 @"description": @"Me testing the video upload to Facebook with the new system."
                                 };

        NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
        SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                requestMethod:SLRequestMethodPOST
                                                          URL:requestURL
                                                   parameters:params];

        [request addMultipartData:videoData
                         withName:@"source"
                             type:@"video/quicktime"
                         filename:[_fURL absoluteString]];
        request.account = facebookAccount;
        [request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response,NSError * error){
            NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"response = %@", responseString);
        }];

是的,我缺少发布流权限,但我似乎无法弄清楚应将其放在哪里,整个代码位于一种方法下,当用户按下按钮时会调用该方法

这很简单。 那是我的实现:

- (void)requestAccessToFacebookAccountWithCompletionHandler:(QCFacebookCommunicatorCompletionHandler)completionHandler {
    [[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForReadStreamPermission] completion:^(BOOL accessForReadingGranted, NSError *error) {
        if (accessForReadingGranted) {
            [[self accountStore] requestAccessToAccountsWithType:[self accountType] options:[self facebookAccountAccessRequestOptionsForPublishStreamPermission] completion:^(BOOL accessForWrittingGranted, NSError *error) {
                if (accessForWrittingGranted) {
                    completionHandler(YES, nil);
                } else {
                    completionHandler(NO, [error userInfo]);
                }
            }];
        } else {
            completionHandler(NO, [error userInfo]);
        }
    }];
}

我只是使用辅助方法来返回带有选项的字典,其他内容与您的相似。

然后,您可以粘贴负责视频上传的代码而不是completionHandler调用,或者可以使用此实现,并且仅在completionHandler中成功== YES的情况下上传视频。

希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM