cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When I try to get a list of files I get a nil in response (Swift 5)

When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

I have a simple method where I want to get a list of the user's files. I took the implementation of this method from your PhotoWatch example. I also added a print at each step to track each step. But when I try to get a response, I get a nil. What's wrong? This user definitely has files in his Dropbox.

I would be grateful for help.

Screen Shot 2020-08-20 at 12.06.12.png

1 Accepted Solution

Accepted Solutions

Re: When I try to get a list of files I get a nil in response (Swift 5)

Greg-DB
Dropboxer

You just need to create the ScopeRequest object before calling the authorizeFromControllerV2 method.

 

As for the error, make sure you're only calling the authorizeFromControllerV2 method once. In your screenshot, I see you're calling authorizeFromControllerV2, and then are also calling a method of your own called "openDropboxAutorization". Are you also calling an authorize method from inside "openDropboxAutorization" by any chance?

View solution in original post

10 Replies 10

Re: When I try to get a list of files I get a nil in response (Swift 5)

Greg-DB
Dropboxer

The response method is given both a "response" and "error" object. If "response" isn't set, you should check "error" to see what went wrong with the call.

Re: When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

I handled the error, the problem was with individual scopes. I have selected the options I want and now I get another error.

API auth error - {
".tag" = "missing_scope";
"required_scope" = "files.metadata.read";
}

 

Screen Shot 2020-08-21 at 10.02.54.png

Re: When I try to get a list of files I get a nil in response (Swift 5)

Greg-DB
Dropboxer

The 'missing_scope' error indicates that while the app is permitted to use that scope, the particular access token you're using to make the API call does not have that scope granted. Adding a scope to your app via the App Console does not retroactively grant that scope to existing access tokens.

 

That being the case, to make any API calls that require that scope, you'll need to get a new access token with that scope.

Re: When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

I created a new token for this account, but I still get this error. It's strange that when I log into the application with this account, I see an another token in the Xcode console. I also try to log into the application under other Dropbox accounts and still get this error. Also I tried disabling all active tokens for this app, but it didn't work.
I can't understand what I'm doing wrong, can you explain in more detail what I should do?
Screen Shot 2020-08-24 at 08.59.02.png

Re: When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

I also noticed that although I have checked the boxes for files.content.read and files.metadata.read, the application for some reason does not request access to them.

Screen Shot 2020-08-24 at 09.58.36.png

IMG_2013.PNG

Re: When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

I even created a new application in AppConsole, made the necessary changes to the Xcode project, but I still get the same error...
API auth error - {
".tag" = "missing_scope";
"required_scope" = "files.metadata.read";
}

Re: When I try to get a list of files I get a nil in response (Swift 5)

Greg-DB
Dropboxer

When enabling a new scope for an app, make sure you click the "Submit" at the bottom of the page, or else the changes won't take effect.

 

And, when configuring the app authorization flow, be sure to specify the particular scopes you want to request. When using SwiftyDropbox, that's done by making a ScopeRequest object with the desired scopes in the "scopes" parameter, and passing that to authorizeFromControllerV2 as shown here. That example only includes "account_info.read", but you would want to add "files.metadata.read" to that list, for example.

Re: When I try to get a list of files I get a nil in response (Swift 5)

VyacheslavB
Helpful | Level 5

At what moment should I create a ScopeRequest object?
I try to do this in the Action of the Login button, but at the time of authorization after clicking Alloy, I receive an Error: Optional("Auth flow failed because of inconsistent state.")
Screen Shot 2020-08-24 at 19.17.53.png

Re: When I try to get a list of files I get a nil in response (Swift 5)

Greg-DB
Dropboxer

You just need to create the ScopeRequest object before calling the authorizeFromControllerV2 method.

 

As for the error, make sure you're only calling the authorizeFromControllerV2 method once. In your screenshot, I see you're calling authorizeFromControllerV2, and then are also calling a method of your own called "openDropboxAutorization". Are you also calling an authorize method from inside "openDropboxAutorization" by any chance?

View solution in original post

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    VyacheslavB Helpful | Level 5
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?