title: Dropbox error 400 invalid_request when loading all paths of the users files
body: <p>I am getting error 400 while trying to retrieve the users full list of files name from the app folder after the user logs in.</p>
  
  <p>I am using this tutorial to set up the the dropbox sdk:
  <a href="https://www.dropbox.com/developers-v1/core/start/ios" rel="nofollow noreferrer">https://www.dropbox.com/developers-v1/core/start/ios</a></p>
  
  <p>but changed the approach a little bit as not all the action is taking place in my app delegate .m file.</p>
  
  <p>Also I had an error after first running the app even though I was doing it as in the tutorial, but after a quick search I found out that I had to add the next lines in my Info.plis for everything to run:
      LSApplicationQueriesSchemes
      
          dbapi-2
      </p>
  
  <p>after doing so I am able to successfully authenticate to dropbox and after I do that I am sending a request to a shared session custom class that hold the rest of my Dropbox functionality and try to get the list of files from inside the app folder, then I get the next error:</p>
  
  <pre><code>App linked successfully!
  [WARNING] DropboxSDK: error making request to /1/metadata/sandbox - (400) invalid_request
   Error loading metadata: Error Domain=dropbox.com Code=400 "(null)" UserInfo={error_description=No auth function available for given request, path=/, error=invalid_request}
  </code></pre>
  
  <p>After I get this error if I put the same code in the viewWillAppear or the viewDidLoad of the same class then the code is executed and it returns and empty dictionary witch means that there are no photos in my app folder and I can proceed with my files upload.</p>
  
  <p>My question is:
  why do I have to restart the app in order for the same call to work and why isn't it working from the start?</p>
  
  <p>Now for my settings:
   1. when I created the app on the dropbox app platform I choosed:
      - API : Dropbox API not dropbox for business api
      - permisions: APP Folder not Full Dropbox
   2. in the info.plis file I added the next values:</p>
  
  <pre><code> &lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;dbapi-2&lt;/string&gt;
      &lt;/array&gt;
  </code></pre>
  
  <p>AND:</p>
  
  <p><a href="https://i.stack.imgur.com/kzexU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kzexU.png" alt="enter image description here"></a></p>
  
  <p>Now in my App delegate.m:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  .........
  [self initDropbox];
  return YES;
  }
  
  - (void)initDropbox{
  
      DBSession *dbSession = [[DBSession alloc]
                              initWithAppKey:@"appKey"
                              appSecret:@"appSecret"
                              root:kDBRootAppFolder]; 
      [DBSession setSharedSession:dbSession];
  
  }
  
  - (BOOL)application:(UIApplication *)app
              openURL:(NSURL *)url
    sourceApplication:(NSString *)source
           annotation:(id)annotation {
      if ([[DBSession sharedSession] handleOpenURL:url]) {
          if ([[DBSession sharedSession] isLinked]) {
              NSLog(@"App linked successfully!");
              // At this point you can start making API calls
              [[NSNotificationCenter defaultCenter] postNotificationName:@"applicationDidLinkWithDropbox"
                                                                  object:self];
  
          }
          return YES;
      }
      // Add whatever other url handling code your app requires here
      return NO;
  }
  </code></pre>
  
  <p>And in my view controller I have:</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated {
  [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(dropBoxDidLink:)
                                                   name:@"applicationDidLinkWithDropbox"
                                                 object:nil];
  //method that gets called after authentication or when the screen is displayed 
  //the methods is called only is it if not running already, I check if it is running with the isBussy bool 
  
      DropBoxSuport *managedObj = [DropBoxSuport sharedInstance];
      BOOL isBussy = managedObj.isUploadingImage;
      if ([managedObj isAuthenticated] &amp;&amp; !isBussy) {
          managedObj.isSingleUpload = NO;
          [managedObj startDropboxBackup];
      }
  
  }
  - (IBAction)didTappedDropboxButton:(id)sender {
  if (![[DBSession sharedSession] isLinked]) {
              [[DBSession sharedSession] linkFromController:self];
          }else{
              [[DBSession sharedSession] unlinkAll];
              dropDownView.firstCellSwitch.on = NO;
          }
  }
  
  - (void) dropBoxDidLink:(NSNotification *)notification {
      if ([[notification name] isEqualToString:@"applicationDidLinkWithDropbox"]) {
  
          dropDownView.firstCellSwitch.on = YES;
          dropDownView.firstCellSwitch.userInteractionEnabled = NO;
  
          DropBoxSuport *managedObj = [DropBoxSuport sharedInstance];
          BOOL isBussy = managedObj.isUploadingImage;
          if ([managedObj isAuthenticated] &amp;&amp; !isBussy) {
              managedObj.isSingleUpload = NO;
              [managedObj startDropboxBackup];
          }
      }
  }
  </code></pre>
  
  <p>And in my custom class(DropBoxSuport.m):</p>
  
  <pre><code>+(instancetype) sharedInstance {
      static dispatch_once_t pred;
      static id shared = nil;
      dispatch_once(&amp;pred, ^{
          shared = [[super alloc] initUniqueInstance];
          [shared initializeRestClient];
      });
      return shared;
  }
  
  -(instancetype) initUniqueInstance {
      return [super init];
  }
  
  - (void)initializeRestClient{
  
      restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
      restClient.delegate = self;
      context = [self appDelegate].managedObjectContext;
  
  }
  
  - (void)startDropboxBackup{
      if (!isUploadingImage &amp;&amp; [self appDelegate].checkForNetwork &amp;&amp; [self isAuthenticated]) {
          isUploadingImage = YES;
           [restClient loadMetadata:@"/"];
      }
  }
  
  #pragma mark - dropbox delegate get file names
  - (void)restClient:(DBRestClient *)client
      loadedMetadata:(DBMetadata *)metadata {
  
      NSMutableArray *tempArray = [[NSMutableArray alloc] init];
      if (metadata.isDirectory) {
          NSLog(@"Folder '%@' contains:", metadata.path);
          for (DBMetadata *file in metadata.contents) {
              if (file.filename) {
                  [tempArray addObject:file.filename];
              }
          }
      }
  
          NSArray *localStoredImages = [[NSArray alloc] initWithArray:[self loadAllCoreDataImagePaths]];
          NSArray *dropboxStoredImages = [[NSArray alloc] initWithArray:tempArray];
  
          differenceArray = [self getDifferenceBetweenArray:localStoredImages andSecondArray:dropboxStoredImages];
          if (differenceArray &amp;&amp; differenceArray.count &gt; 0) {
              [self startDropboxUpload];
          }else{
              isUploadingImage = NO;
              errorCount = 0;
              currentImageUploaded = 0;
          }
  
  
  
  
  
  }
  
  - (void)restClient:(DBRestClient *)client
  loadMetadataFailedWithError:(NSError *)error {
      NSLog(@"Error loading metadata: %@", error);
      isUploadingImage = NO;
      errorCount = 0;
      currentImageUploaded = 0;
  }
  </code></pre>
  
  <p>So pretty much this is my code and how I use it, but as I sad the code only happens when the user authenticates for the first time and I try to get the folder names. Also tried to get the folder later without restarting the app and the same error occurred. But if I restart the app everything works fine.</p>
  
  <p>Any help is much appreciated</p>