Question

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);
    }];
}
Was it helpful?

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.

OTHER TIPS

All of your code after NSURL *videourl should be moved to another method. Currently it is being executed while the requestAccessToAccountsWithType: request is in progress so the facebookAccount reference isn't available yet. So, the new method that you create and move that code to should be called from the completion block if granted is true.

Note hat you can't just immediately request publish permissions. You must request read permissions first and then, once it's been granted, request publish permissions.

The problem seems to be with your NSDictionary creation.

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

you see you are passing keys first and objects later, where NSDictionary calls +dictionaryWithObjectsAndKeys in this case...

try using the correct format like:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"###############", ACFacebookAppIdKey, 
                         [NSArray arrayWithObject:@"publish_stream"], ACFacebookPermissionsKey, 
                         nil];

this should work.

see the same question here: Getting "Error Code 8" When Calling [ACAccountStore requestAccessToAccountsWithType] - iOS Facebook

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top