Getting OauthException when uploading a video to facebook

224 Views Asked by At

I am trying to upload a video on an iPhone to the user's facebook timeline using Social Framework. I used the snippet given in this answer. Here is my code:

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

As you can see, I first requested read permission(email) then, requested publish permission if the first request is granted. The code works fine, all the permissions are granted and the app begins uploading video(I can see this in my network monitoring tool). However, after video is uploaded I get this error:

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

What might be the problem here? I read some other SO posts and seems it is possible thet the error is originated from Facebook's side. Any suggestions?

0

There are 0 best solutions below