title: Upload Facebook Photo And Auto Log User Out (Kiosk App)
body: <p>I have an iPad app designed for use in a kiosk environment. </p>
  
  <p>The user flow should be </p>
  
  <ul>
  <li>Take Photo</li>
  <li>Choose photo from iPad Album view </li>
  <li>Share to Facebook and / or Twitter</li>
  <li>Automatically log user out after image has been posted</li>
  </ul>
  
  <p>I have the auto-logout of Twitter working properly, my issue is with the Facebook portion.</p>
  
  <p>I have implemented the Graph API for internal testing, and would love to be able to post a complete story this way, but I don't think there is a way to log out from the Facebook app once the authorization and post is complete.</p>
  
  <p>For a fallback, I can use the Feed Dialog and auto-logout from there, but as far as I can tell, there is no way to upload a local image for sharing to Facebook from there.</p>
  
  <p>My Facebook Sharing code is as follows:</p>
  
  <pre><code>- (IBAction)facebookShare:(id)sender {
  
  /// Package the image inside a dictionary
  NSArray* image = @[@{@"url": self.mergeImages, @"user_generated": @"true"}];
  
  // Create an object
  id&lt;FBGraphObject&gt; object =
  [FBGraphObject openGraphObjectForPostWithType:@"me/feed:photo"
                                          title:@"a photo"
                                          image:self.mergeImages
                                            url:nil
                                    description:nil];
  
  // Create an action
  id&lt;FBOpenGraphAction&gt; action = (id&lt;FBOpenGraphAction&gt;)[FBGraphObject graphObject];
  
  // Set image on the action
  [action setObject:image forKey:@"image"];
  
  // Link the object to the action
  [action setObject:object forKey:@"photo"];
  
  // Hardcode the location based on Facebook Place ID
  id&lt;FBGraphPlace&gt; place = (id&lt;FBGraphPlace&gt;)[FBGraphObject graphObject];
  [place setId:@"279163865580772"]; // Singley + Mackie
  [action setPlace:place];
  
  // Check if the Facebook app is installed and we can present the share dialog
  FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
  params.action = action;
  params.actionType = @"me/feed:share";
  
  // If the Facebook app is installed and we can present the share dialog
  if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
      // Show the share dialog
      [FBDialogs presentShareDialogWithOpenGraphAction:action
                                            actionType:@"photo_overlay:share"
                                   previewPropertyName:@"photo"
                                               handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                   if(error) {
                                                       // An error occurred, we need to handle the error
                                                       // See: https://developers.facebook.com/docs/ios/errors
                                                       // NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                                   } else {
                                                       // Success
                                                       NSLog(@"result %@", results);
                                                   }
                                              }];
  
      // If the Facebook app is NOT installed and we can't present the share dialog
  } else {
      // Put together the Feed dialog parameters
      NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     @"name",
                                     @"caption",
                                     @"description",
                                     @"link",
                                     @"picture",
                                     nil];
      // Show the feed dialog
      [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                             parameters:params
                                                handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                    if (error) {
                                                        // An error occurred, we need to handle the error
                                                        // See: https://developers.facebook.com/docs/ios/errors
                                                        // NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                                    } else {
                                                        if (result == FBWebDialogResultDialogNotCompleted) {
                                                            // User cancelled.
                                                            NSLog(@"User cancelled.");
                                                        } else {
                                                            // Handle the publish feed callback
                                                            NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
  
                                                            if (![urlParams valueForKey:@"post_id"]) {
                                                                // User cancelled.
                                                                NSLog(@"User cancelled.");
  
                                                            } else {
                                                                // User clicked the Share button
                                                                NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                                NSLog(@"result %@", result);
                                                              }
                                                        }
                                                    }
  
                                                    // Auto log the user out
                                                    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                                                    NSLog(@"defaults fbDidLogout  ........%@",defaults);
                                                    if ([defaults objectForKey:@"FBAccessTokenKey"])
                                                    {
                                                        [defaults removeObjectForKey:@"FBAccessTokenKey"];
                                                        [defaults removeObjectForKey:@"FBExpirationDateKey"];
                                                        [defaults synchronize];
                                                    }
  
                                                    NSHTTPCookie *cookie;
                                                    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
                                                    for (cookie in [storage cookies])
                                                    {
                                                        NSString* domainName = [cookie domain];
                                                        NSRange domainRange = [domainName rangeOfString:@"facebook"];
                                                        if(domainRange.length &gt; 0)
                                                        {
                                                            [storage deleteCookie:cookie];
                                                        }
                                                    }
  
                                                    [FBSession.activeSession closeAndClearTokenInformation];
  
                                                }];
  
  }
  }
  // A function for parsing URL parameters.
  - (NSDictionary*)parseURLParams:(NSString *)query {
      NSArray *pairs = [query componentsSeparatedByString:@"&amp;"];
      NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
      for (NSString *pair in pairs) {
          NSArray *kv = [pair componentsSeparatedByString:@"="];
          NSString *val =
          [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
          params[kv[0]] = val;
      }
      return params;
  }
  </code></pre>
  
  <p>I have searched Stack Overflow far and wide for an answer to this, but have found no solutions. </p>