title: How to get Facebook access key from code
body: <p>Perplexing quandary: When I get my friends list with one URL I get the list back fine, using the same URL but with a query string (?fields=id,name,picture), and the exact same permissions, I get an error indicating "An active access token must be used to query information about the current user." What gives?</p>
  
  <p>The permissions currently in effect are publish_stream, email, and read_stream.  Why would adding that query string mess it up?  The only thing I can think of is that the access key I have is not what I think. Is there a way to pull the actual access key out, expose it in an NSLog, and then test it on the graph explorer?</p>
  
  <p>The URL that works is:</p>
  
  <pre><code>https://graph.facebook.com/me/friends
  </code></pre>
  
  <p>The URL that doesn't is:</p>
  
  <pre><code>https://graph.facebook.com/me/friends?fields=id,name,picture
  </code></pre>
  
  <p>This is the code that actually get the permissions. In fact this is the same code that Stuart Breckenridge offered up freely on GitHub (thanks dude!) It seems to work fine as long as I am not appending '?fields=name,id,picture' to the end of the api call:</p>
  
  <pre><code>-(void)requestPermissions
  {
      if (debugF) NSLog(@"FAM: requestPermissions");
      // Specify the Facebook App ID.
      _facebookAppID = @"123456789123456"; // You Must Specify Your App ID Here.
  
      // Submit the first "read" request.
      // Note the format of the facebookOptions dictionary. You are required to pass these three keys: ACFacebookAppIdKey, ACFacebookAudienceKey, and ACFacebookPermissionsKey
      // Specify the read permission
      _facebookPermissions = @[@"email"];
  
      // Create &amp; populate the dictionary the dictionary
      _facebookOptions = @{   ACFacebookAppIdKey : _facebookAppID,
                           ACFacebookAudienceKey : ACFacebookAudienceFriends,
                        ACFacebookPermissionsKey : _facebookPermissions};
  
      _facebookAccountType = [_facebookAccountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
  
      [_facebookAccountStore requestAccessToAccountsWithType:_facebookAccountType options:_facebookOptions completion:^(BOOL granted, NSError *error)
       {
           // If read permission are granted, we then ask for write permissions
           if (granted) {
  
               _readPermissionsGranted = YES;
  
               // We change the _facebookOptions dictionary to have a publish permission request
               _facebookPermissions =  @[@"publish_stream", @"read_stream", @"friends_photos"];
  
               _facebookOptions = @{         ACFacebookAppIdKey : _facebookAppID,
                                          ACFacebookAudienceKey : ACFacebookAudienceFriends,
                                       ACFacebookPermissionsKey : _facebookPermissions};
  
  
               [_facebookAccountStore requestAccessToAccountsWithType:_facebookAccountType options:_facebookOptions completion:^(BOOL granted2, NSError *error)
                {
                    if (granted2)
                    {
                        _publishPermissionsGranted = YES;
                        // Create the facebook account
                        _facebookAccount = [[ACAccount alloc] initWithAccountType:_facebookAccountType];
                        _arrayOfAccounts = [_facebookAccountStore accountsWithAccountType:_facebookAccountType];
                        _facebookAccount = [_arrayOfAccounts lastObject];
                    }
  
                    // If permissions are not granted to publish.
                    if (!granted2)
                    {
                        if (debugF) NSLog(@"Publish permission error: %@", [error localizedDescription]);
                        _publishPermissionsGranted = NO;
                    }
  
                }];
           }
  
           // If permission are not granted to read.
           if (!granted)
           {
               if (debugF) NSLog(@"Read permission error: %@", [error localizedDescription]);
               _readPermissionsGranted = NO;
  
               if ([[error localizedDescription] isEqualToString:@"The operation couldn’t be completed. (com.apple.accounts error 6.)"])
               {
                   [self performSelectorOnMainThread:@selector(showError) withObject:error waitUntilDone:NO];
               }
           }
       }];
  }
  </code></pre>