Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us here!
Forum Discussion
Bob S.15
9 years agoCollaborator | Level 9
migrating from API 1 to 2 - how do I know if I have OAuth 1 tokens?
I am finally getting around to updating my OLD apps from the original Dropbox IOS API to the new one. I'm looking at the migration guide, and the first thing it says is to check my OAuth tokens to se...
Bob S.15
9 years agoCollaborator | Level 9
Hey Greg,
Yes that worked, thanks!
In the process of debugging this I went through all of my various simulators and devices, because I don't know how to remove the OAuth2 tokens once they are on there. I ran the old app to get the old tokens installed, then ran the new one to test the retrieval. Is there any way to remove the new tokens in order to re-test the transfer?
Bob
Greg-DB
Dropbox Community Moderator
9 years agoYea, you can use DBOAuthManager.clearStoredAccessToken for specific tokens, or DBOAuthManager.clearStoredAccessTokens for all tokens.
- Bob S.159 years agoCollaborator | Level 9
Ok, thanks Greg.
Also, when I use DBFILESgetMetadata, is there any way to tell if the path is a file or a folder? In the old SDK there was an 'isDirectory' field of the metadata structure, but I don't see one for DBFILESMetadata. ?
Also, if it IS a folder, then how do you access the contents of the folder? With the old SDK I uses a loop like this:
for (DBMetadata *file in metadata.contents)
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
You can use isKindOfClass to check the type:
https://github.com/dropbox/dropbox-sdk-obj-c/blob/8d4fcca08a6673af35cf6e116810b13e3e6507e9/README.md#response-handling-edge-cases - Bob S.159 years agoCollaborator | Level 9
OK thanks, and how would you access the contents of the folder, is that included in the metadata or do you have to issue another call to get that? Would I have to use listFolder?
- Greg-DB9 years ago
Dropbox Community Moderator
Yes, you should use listFolder (and listFolderContinue) to get the contents of any given folder. - Bob S.159 years agoCollaborator | Level 9
Hey Greg,
If getMetaData returns an error, how do you retrieve the error information from DBFILESGetMetadataError? It looks like it only contains a path and a tag, and I can't tell what the tag is. The docs say it represents the "union's current tag state", but it doesn't show any values. Is there some other way to get information about why it failed or what the error is ?
Thanks,
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
You can use the "is" methods to check which member of the error union a particular instance of the error is, then you can access the respective property for the specific error value, as shown here:
https://github.com/dropbox/dropbox-sdk-obj-c#route-specific-errors
The documentation details which methods/properties are available for any given type, e.g., for DBFILESGetMetadataError:
https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESGetMetadataError.html - Bob S.159 years agoCollaborator | Level 9
Thanks for the reply. I get that I can use the 'is' commands to check the error, but in the case of the metadata, there is a path and a tag. The path is pretty self evident. But what is the tag? The docs don't seem to provide any details about what that is. I'm just wondering in the case of an error, how I would go about determining the cause or reason. The path I already know. And it doesn't look like the tag tells me anything. Does that make sense?
Thanks!
- Greg-DB9 years ago
Dropbox Community Moderator
The "tag" is the way the API describes which member of the union the object is. The SDK uses it to determine what the "is" methods return. So, you don't need to access tag directly, as long as you use the "is" methods.
To get the actual error information, use the respective field. For example, DBFILESGetMetadataError.path gives you a DBFILESLookupError, which itself has various "is" methods to tell you which error it was (and so on, for any further nested errors).
- Bob S.159 years agoCollaborator | Level 9
Oh, I see, the path contains the error information. I had assumed the path was just the file pathname.
Thanks!
- Bob S.159 years agoCollaborator | Level 9
Hey Greg,
With the old API, when I got a file's metadata, the returned DBMetadata structure included the filename, the path, the revision, the total bytes, and the last modified date. Isn't that stuff commonly considered the metadata? With the new API, getMetadata seems like it only returns the filename and path, is that correct? How do I access that other information?
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
This information is still available, but it depends on the object type. The name and path are available on all DBFILESMetadata objects:
https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESMetadata.html
Modified time, size, rev, etc. are available on DBFILESFileMetadata instances:
https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESFileMetadata.html
(DBFILESFileMetadata is a sub-type of DBFILESMetadata.)
You can see an example of how to check and cast these types here:
https://github.com/dropbox/dropbox-sdk-obj-c#response-handling-edge-cases - Bob S.159 years agoCollaborator | Level 9
OK, thanks, I got it now.
Also - is it okay to use the pathDisplay variable as a replacement for the old API's 'path' variable? The docs say pathDisplay is only for display purposes, as if it might be incorrect sometimes. But the other option is 'pathLower' , which is a lower-case version. So what do you use if you just want the exact pathname, like what you had in the old API?
- Greg-DB9 years ago
Dropbox Community Moderator
Yes, v2's pathDisplay is the equivalent of v1's path. You should use that whenever you want to display the correctly cased version of the path. For the API calls themselves though, e.g., if you're taking the path from the metadata to then download the file, you should use pathLower. The Dropbox API is case-insensitive, and pathLower is the canonicalized version of the path. (Most of the time this doesn't matter, but there are a few edge cases that you can avoid by using pathLower when specifying paths in API calls.) - Bob S.159 years agoCollaborator | Level 9
If the API is case insensitive, what happens when you upload a file with capitalization, and then try to download it again later? Wouldn't it lose the capitalization? Like, if I upload from once device and download to another, then if I used pathLower to create the new file, I would lose the original capitalization...
One reason why these docs are so confusing to me, and why I asked that previous question, is that for example, getMetadata says it returns a DBFILESMetadata object. But if you go to the docs for that object, there is no indication that there are subclasses of that object for the various types -- file, folder, etc. How would I know that if you hadn't told me? Is there documentation I'm missing?
So that leads me to another question, sorry! If I use -getMetadata:includeMediaInfo:includeDeleted:includeHasExplicitSharedMembers:
then I assume you can tell whether the file/folder is deleted by the type of DBFILESMetadata object that is returned -- a DBFILESDeletedMetadata object, right? But then how do to tell if it was a file or a folder -- because normally you would check for a
DBFILESFolderMetadata or DBFILESFileMetadata object for that. ??
Finally, the getMetadata docs say this about the 'includeDeleted' argument:
"If true, DeletedMetadata will be returned for deleted file or folder, otherwise notFound in DBFILESLookupError will be returned." What does this mean? Say I have a path to a file that does exist, and I call getMetadata with 'includeDeleted' = true. Will I get both a DBFILESFileMetadata object in the return, as well as a 'notFound' in the DBFilesLookupError? And where would that DBFilesLookupError be? Would it be part of the returned DBFILESGetMetadataError or the DBRequestError?
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
The API is case-insensitive, but case-preserving. So when you upload a file with a certain casing, that will be preserved in pathDisplay, though you can reference that file with a lower-cased version of the path.
In the re-creation scenario you describe, you can certainly re-use pathDisplay to create it with the casing you want.
And thanks, that's good feedback regarding the sub-classes in the documentation. I'll send it along to the team.
If you use includeDeleted with getMetadata, the resulting DBFILESMetadata will be one of DBFILESFileMetadata, DBFILESFolderMetadata, DBFILESDeletedMetadata. Deleted entries are neither files nor folders though. They just indicate that there was previously something at that path. (That something could have, at different points in time, been a file and a folder.)
For getMetadata, if you set includeDeleted to true, for a deleted entry, the "result" will be a DBFILESDeletedMetadata. If you set includeDeleted to false, the "route error" will contain a DBFilesLookupError (nested in a DBFILESGetMetadataError.path, to be strictly accurate.) You won't get both though.
You can see an example of the separation of the result, route error, and error for an RPC call like this here:
https://github.com/dropbox/dropbox-sdk-obj-c#rpc-style-request
- Bob S.159 years agoCollaborator | Level 9
Okay -- thanks for all of this help!
I was wondering, is there any way to cause Dropbox errors intentionally for testing? For example I would like to test the various upload errors that might happen.
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
No, there isn't a way to trigger various errors like that (short of actually producing the relevant conditions), but I'll pass this along as a feature request. - Bob S.159 years agoCollaborator | Level 9
Okay. Another question -- can I use
([DropboxClientsManager authorizedClient] != nil)
as a replacement for
[[DBSession sharedSession] isLinked]
? Or are those two not equivalent? Is there something better I should use?
- Greg-DB9 years ago
Dropbox Community Moderator
Yes, that's it. - Bob S.159 years agoCollaborator | Level 9
Hey Greg,
I am getting this kind of stuff printed to the console when I use the Dropbox API. I'm not getting errors with the API calls, though. Is this normal?
Thanks
Bob
2017-02-15 13:38:52.256303 Headspace[18414:3298160] [] nw_host_stats_add_src recv too small, received 24, expected 28 2017-02-15 13:38:52.259067 Headspace[18414:3298160] [] __nwlog_err_simulate_crash simulate crash already simulated "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available" 2017-02-15 13:38:52.259526 Headspace[18414:3298160] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace: [x86_64] libnetcore-856.30.16 0 libsystem_network.dylib 0x0000000112e2e666 __nw_create_backtrace_string + 123 1 libnetwork.dylib 0x0000000116b1d006 nw_socket_add_input_handler + 3164 2 libnetwork.dylib 0x0000000116afa555 nw_endpoint_flow_attach_protocols + 3768 3 libnetwork.dylib 0x0000000116af9572 nw_endpoint_flow_setup_socket + 563 4 libnetwork.dylib 0x0000000116af8298 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612 5 libnetwork.dylib 0x0000000116b13ae1 nw_endpoint_handler_path_change + 1261 6 libnetwork.dylib 0x0000000116b13510 nw_endpoint_handler_start + 570 7 libnetwork.dylib 0x0000000116b2b1f9 nw_endpoint_resolver_start_next_child + 2240 8 libdispatch.dylib 0x0000000112bab978 _dispatch_call_block_and_release + 12 9 libdispatch.dylib 0x0000000112bd50cd _dispatch_client_callout + 8 10 libdispatch.dylib 0x0000000112bb2e17 _dispatch_queue_serial_drain + 236 11 libdispatch.dylib 0x0000000112bb3b4b _dispatch_queue_invoke + 1073 12 libdispatch.dylib 0x0000000112bb6385 _dispatch_root_queue_drain + 720 13 libdispatch.dylib 0x0000000112bb6059 _dispatch_worker_thread3 + 123 14 libsystem_pthread.dylib 0x0000000112f7e4de _pthread_wqthread + 1129 15 libsystem_pthread.dylib 0x0000000112f7c341 start_wqthread + 13
- Bob S.159 years agoCollaborator | Level 9
Hey Greg,
I'm trying to compare the behavior of this new API with the old one. But I can't find the documentation for the old Rest API for iOS. I want to know if the old loadFile:intoPath call (which downloads a file) automatically overwrote any existing file on the device, or if it generated an error? It looks like it is automatically overwriting, but I wanted to make sure or find out if there was a setting for whether to overwrite or not. I know that the new call has an argument for that.
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
The old iOS Core SDK didn't have good documentation unfortunately. Here are the relevant methods/documentation in the comments though:
/* Loads the file contents at the given root/path and stores the result into destinationPath */ - (void)loadFile:(NSString *)path intoPath:(NSString *)destinationPath; /* This will load a file as it existed at a given rev */ - (void)loadFile:(NSString *)path atRev:(NSString *)rev intoPath:(NSString *)destPath;
There wasn't a parameter for controlling overwriting at the destination.
The actual code is:
// Everything's OK, move temp file over to desired file [fileManager removeItemAtPath:resultFilename error:nil]; BOOL success = [fileManager moveItemAtPath:tempFilename toPath:resultFilename error:&moveError];
So, yes, it seems it overwrote existing files by removing anything at the destination first, and then moving in the downloaded data (which it saved at a temporary location beforehand).
- Bob S.159 years agoCollaborator | Level 9
OK, great.
Also, what should I use as a replacement for this check?
if ([DBSession sharedSession])
This is just at the beginning of the program to make sure Dropbox is there, but not necessarily logged in. The [DropboxClientsManager setupWithAppKey:DROPBOX_APP_KEY] doesn't return any value, so I can't use that.
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
The new SDK doesn't have a concept exactly like that. As long as you call setupWithAppKey in application: didFinishLaunchingWithOptions: you should be fine. I'm not sure I understand your use case though. Is there a particular scenario you're concerned about that wouldn't work with that? - Bob S.159 years agoCollaborator | Level 9
It's probably fine then. In the old version I guess there was a chance that the DBSession would fail for some reason?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,011 PostsLatest Activity: 2 years ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!