OGeek|极客世界-中国程序员成长平台

标题: ios - 从 iOS 将视频上传到 facebook - 无法向用户请求登录权限,错误代码 6 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:20
标题: ios - 从 iOS 将视频上传到 facebook - 无法向用户请求登录权限,错误代码 6

我正在使用 iOS 6 中的社交框架将 facebook 视频上传集成到我的应用程序中。但是,当我运行该程序时没有任何反应,而是收到以下错误:

The operation couldn’t be completed. (com.apple.accounts error 6.)

"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}"

下面是我的代码,前半部分是我从 tutorial 实现的. granted 设置为 false,导致第一个错误。

- (void)uploadToFb {

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                               ACFacebookAppIdKey: @"2************",
                               ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                               ACFacebookAudienceKey: ACFacebookAudienceFriends
    };

    [accountStore requestAccessToAccountsWithType:facebookAccountType
                                          optionsptions completion:^(BOOL granted, NSError *e) {

          if (granted) 
          {
              NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
              facebookAccount = [accounts lastObject];
          }
          else
          { 
           NSLog(@"Error %@", e.localizedDescription);                                              }

          }
    }];

    NSURL *videourl = [NSURL URLWithString"https://graph.facebook.com/me/videos"];

    NSString *filePath = [outputURL path];
    NSURL *pathURL = outputURL;
    NSData *videoData = [NSData dataWithContentsOfFile:filePath];

    NSDictionary *params = @{
    @"title": @"Face Puppets Video",
    @"description": @"A funny video I made with the #FacePuppets iOS app."
    };

    SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                  requestMethod:SLRequestMethodPOST
                                                            URL:videourl
                                                     parameters:params];
    [uploadRequest addMultipartData:videoData
                           withName"source"
                               type"video/quicktime"
                           filename:[pathURL absoluteString]];

    uploadRequest.account = facebookAccount;

    [uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
        if(error){
            NSLog(@"Error %@", error.localizedDescription);
        }else
            NSLog(@"%@", responseString);
    }];
}



Best Answer-推荐答案


嗨,这是一个非常好的分享示例iOS (Wiki) (Sample Project for iOS, ~3 MB)使用它,您可以将视频分享到 Facebook、YouTube、Flicker、Vimeo 查看上面的链接并测试此示例。

你需要在ESSViewController.m类中设置你的AppId 在这个方法中:

- (IBAction)facebookid)sender
{
    self.fb = [[[ESSFacebook alloc] initWithDelegate:self
                                               appID"youAppID"
                                           appSecret"secret"] autorelease];
    NSURL *url = [[NSBundle mainBundle] URLForResource"IMG_1203" withExtension"MOV"];
    [self.fb uploadVideoAtURL:url];
}

这可能是 Facebook 的旧版本,但用于获取有关如何处理来自 ourApp 的共享视频的想法。

关于ios - 从 iOS 将视频上传到 facebook - 无法向用户请求登录权限,错误代码 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18653228/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4