1

我正在尝试使用社交框架将 iPhone 上的视频上传到用户的 Facebook 时间线。我使用了这个答案中给出的片段。这是我的代码:

- (void)performActivity {
NSLog(@"sharing on facebook.");

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

ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSDictionary *options = @{ACFacebookAppIdKey : @"***", ACFacebookPermissionsKey : @[@"email"], ACFacebookAudienceKey:ACFacebookAudienceFriends};

[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
    if (granted) {

        NSDictionary *options = @{ACFacebookAppIdKey : @"***", ACFacebookPermissionsKey : @[@"publish_stream"], ACFacebookAudienceKey:ACFacebookAudienceFriends};

        [accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
            if (granted) {
                NSLog(@"Publishing");
                ACAccount *fbAccount = [accountStore accountsWithAccountType:facebookAccountType][0];

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

                NSURL *pathURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@session.mov", NSTemporaryDirectory()]];
                NSData *videoData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@session.mov", NSTemporaryDirectory()]];
                NSDictionary *params = @{
                                         @"title": @"Nebuu",
                                         @"description": @"mebuu"
                                         };

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

                uploadRequest.account = fbAccount;

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

如您所见,我首先请求读取权限(电子邮件),然后如果第一个请求被授予,则请求发布权限。代码工作正常,所有权限都被授予并且应用程序开始上传视频(我可以在我的网络监控工具中看到这一点)。但是,上传视频后,我收到此错误:

{
  "error": {
    "message": "An unexpected error has occurred. Please retry your request later.",
    "type": "OAuthException"
  }
}

这里可能有什么问题?我阅读了其他一些 SO 帖子,似乎错误可能来自 Facebook 方面。有什么建议么?

4

0 回答 0