简体   繁体   English

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

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

I am simply trying to integrate Facebook sharing into my app, my app's end product is a video hence uploading and sharing the final compilation with friends is what i have in mind, I am using native social framework with ACAccount Framework, for my app to work there seems to be weird logic from Facebook that i need to ask for read permission before i ask for publish_stream permission and that they cant be immediately after(read somewhere), my question is where and how should i implement this logic in my code, heres my code 我只是想将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);
        }];

Yes I am missing publish stream permission but i cant seem to figure out where should i put it, this whole code is under one method which is called when user presses a button 是的,我缺少发布流权限,但我似乎无法弄清楚应将其放在哪里,整个代码位于一种方法下,当用户按下按钮时会调用该方法

It is very simple. 这很简单。 That is my implementation of it: 那是我的实现:

- (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]);
        }
    }];
}

I just use a helper methods to return dictionaries with options, other stuff is similar to yours. 我只是使用辅助方法来返回带有选项的字典,其他内容与您的相似。

Then, you can paste your code that is responsible for video uploading instead of the completionHandler calls, or you can use this implementation, and upload video only if the success == YES in completionHandler. 然后,您可以粘贴负责视频上传的代码而不是completionHandler调用,或者可以使用此实现,并且仅在completionHandler中成功== YES的情况下上传视频。

Hope it helps! 希望能帮助到你!

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

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