title: iOS using Facebook graph API for post without share dialog?
body: <p>I want to use Facebook graph API to share on Facebook through my app, without presenting share dialog.But on reading various threads on internet i'm really confused about how to achieve this. i found <a href="https://stackoverflow.com/questions/9328001/using-facebook-graph-api-on-ios">this post</a> on stack overflow but didn't able to find out how to make it works.</p>
  
  <p>Can anyone give me step by step guideline or source code. any help would be highly appreciated.</p>
  
  <p><strong>Edit:</strong> code i used so far-</p>
  
  <pre><code>- (IBAction)StatusUpdateWithAPICalls:(id)sender {
  
      [self openSessionForReadPermissions];
  }
  - (void)openSessionForReadPermissions
  {
      [FBSession openActiveSessionWithReadPermissions:nil
                                         allowLoginUI:YES
                                    completionHandler:
       ^(FBSession *session,
         FBSessionState state, NSError *error) {
  
           //this is called even from the reauthorizeWithPublishPermissions
           if (state == FBSessionStateOpen &amp;&amp; !error)
           {
               //[self openSessionForPublishPermissions];
               //dispatch_async(dispatch_get_current_queue(), ^{
                   [self openSessionForPublishPermissions];
               //});
           }
           else if (state == FBSessionStateClosedLoginFailed)
           {
               [FBSession.activeSession closeAndClearTokenInformation];
  
             //  [[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification object:session];
           }
       }];
  }
  -(void)openSessionForPublishPermissions
  {
      // We will post on behalf of the user, these are the permissions we need:
      NSArray *permissionsNeeded = @[@"publish_actions"];
  
      // Request the permissions the user currently has
      [FBRequestConnection startWithGraphPath:@"/me/permissions"
                            completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                if (!error){
                                    // Parse the list of existing permissions and extract them for easier use
                                    NSMutableArray *currentPermissions = [[NSMutableArray alloc] init];
                                    NSArray *returnedPermissions = (NSArray *)[result data];
                                    for (NSDictionary *perm in returnedPermissions) {
                                        if ([[perm objectForKey:@"status"] isEqualToString:@"granted"]) {
                                            [currentPermissions addObject:[perm objectForKey:@"permission"]];
                                        }
                                    }
  
                                    // Build the list of requested permissions by starting with the permissions
                                    // needed and then removing any current permissions
                                    NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:permissionsNeeded copyItems:YES];
                                    [requestPermissions removeObjectsInArray:currentPermissions];
  
                                    NSLog(@"Asking: %@", requestPermissions);
  
                                    // If we have permissions to request
                                    if ([requestPermissions count] &gt; 0){
                                        // Ask for the missing permissions
                                        [FBSession.activeSession requestNewPublishPermissions:requestPermissions
                                                                              defaultAudience:FBSessionDefaultAudienceFriends
                                                                            completionHandler:^(FBSession *session, NSError *error) {
                                                                                if (!error) {
                                                                                    // Permission granted, we can request the user information
                                                                                    [self makeRequestToUpdateStatus];
                                                                                } else {
                                                                                    // An error occurred, handle the error
                                                                                                                                                            NSLog(@"%@", error.description);
                                                                                }
                                                                            }];
                                    } else {
                                        // Permissions are present, we can request the user information
                                        [self makeRequestToUpdateStatus];
                                    }
  
                                } else {
                                    // There was an error requesting the permission information
                                    // See our Handling Errors guide: https://developers.facebook.com/docs/ios/errors/
                                    NSLog(@"%@", error.description);
                                }
                            }];
  }
  
  - (void)makeRequestToUpdateStatus {
  
      // NOTE: pre-filling fields associated with Facebook posts,
      // unless the user manually generated the content earlier in the workflow of your app,
      // can be against the Platform policies: https://developers.facebook.com/policy
  
      [FBRequestConnection startForPostStatusUpdate:@"User-generated status update."
                                  completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                      if (!error) {
                                          // Status update posted successfully to Facebook
                                          NSLog(@"result: %@", result);
                                      } else {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"%@", error.description);
                                      }
                                  }];
  }
  </code></pre>
  
  <p>but i getting this error-</p>
  
  <pre><code>Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled" UserInfo=0x78788e60 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled, NSLocalizedFailureReason=com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled, com.facebook.sdk:ErrorSessionKey=&lt;FBSession: 0x787ac750, state: FBSessionStateOpen, loginHandler: 0x787ac710, appID: 4201XXXXXXXXXXX, urlSchemeSuffix: , tokenCachingStrategy:&lt;FBSessionTokenCachingStrategy: 0x7a1c1b50&gt;, expirationDate: 2015-04-20 06:48:00 +0000, refreshDate: 2015-02-19 09:39:47 +0000, attemptedRefreshDate: 0000-12-30 00:00:00 +0000, permissions:(
      "public_profile"
  )
  </code></pre>
  
  <p>And i'm not sure if i'm doing it right. please suggest me.</p>