Search code examples
iosobjective-cfacebookfacebook-graph-apisocial-framework

Uploading video to facebook from iOS -- unable to request log in permission from user, error code 6


I'm using the social framework in iOS 6 to integrate facebook video uploading into my app. However, nothing happens when I run the program, and I instead receive these errors:

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}}"

Below is my code, the first half of which I implemented from this tutorial. granted is set to false, causing the first error.

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

Solution

  • Hi Here it is a very nice Sharing example iOS (Wiki) (Sample Project for iOS, ~3 MB) Using this you can share Video in to Facebook, YouTube, Flicker, Vimeo Take a look above link and test this Example.

    You need to set You AppId in to ESSViewController.m class In this Method:

    - (IBAction)facebook:(id)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];
    }
    

    Might Be this is an Old virsion of Facebook but for getting Idea about how to process for share Video from ourApp.