Last active
December 28, 2015 12:05
-
-
Save phawk/fa1099873a46a4d4a0d0 to your computer and use it in GitHub Desktop.
Dropbox cursor issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The examples are in Ruby using RestClient (an http library) | |
# Already have a cursor for this user retreived the last time I called /2/files/list_folder/continue | |
# 1AAFFUB2KR3h0S0317__4aWVmvEQwDmIR2fdxsGL4cZGqiZjavby0HkZT70COXZm6XlswiDTQXSM7ir1qZX9uGoKGI9FbI7dSiquLv9-shzV8qOb126UToXHiKfe_oDFRzCg | |
resp = RestClient.post( | |
"https://api.dropboxapi.com/2/files/list_folder/continue", | |
{ | |
cursor: "1AAFFUB2KR3h0S0317__4aWVmvEQwDmIR2fdxsGL4cZGqiZjavby0HkZT70COXZm6XlswiDTQXSM7ir1qZX9uGoKGI9FbI7dSiquLv9-shzV8qOb126UToXHiKfe_oDFRzCg" | |
}.to_json, | |
{ | |
Authorization: "Bearer #{user.dropbox_access_token}", | |
content_type: :json, | |
accept: :json | |
} | |
) | |
# Calling the above returns the following JSON: | |
# {"entries": [], "cursor": "1AAFOsBe9ReGjUPaDHb57U5pC9GlEVC0qcb28I5tTuvRWsKqhguzceScCuUghFuw5NDZltu6UcdWKNkf7IrieedGpBt09Z6HEYwShwltweSC6Z02rBh7CxYSHeEzdnMOJ7Pc", "has_more": false} | |
# We then take this new cursor and store it. | |
# | |
# | |
# Before I do anything I’ll also call off to list_folder with the recursive option set to true, simply to grab another cursor | |
resp = RestClient.post( | |
"https://api.dropboxapi.com/2/files/list_folder", | |
{ | |
path: "", | |
recursive: true | |
}.to_json, | |
{ | |
Authorization: "Bearer #{user.dropbox_access_token}", | |
content_type: :json, | |
accept: :json | |
} | |
) | |
# Cursor comes back with: | |
# 1AAH9pUapmbJLMwj9jgrhh-IGNGsqRqK_wjRlo8dsSLNYpKCvcN59DamCACNTKETBxeLKqjmcEUqB-t7gWNLTPaPr9c0-jB9WlzvnMkVT0MJihx9_G_vlJrMmRvEcvIJqZTo | |
# | |
# And the full json response is: | |
# https://gist.github.com/phawk/d60ab38151eb8b6fa43c | |
# Now I will create a new folder in the dropbox and add an image to the root folder and also inside this new folder | |
# | |
# The files I have created are as follows: | |
# - /City Hall Spire.jpg | |
# - (folder) /star labs | |
# - /star labs/DSC00845.jpg | |
# We’ll go off first with the cursor retrieved as part of the /list_folder/continue call | |
resp = RestClient.post( | |
"https://api.dropboxapi.com/2/files/list_folder/continue", | |
{ | |
cursor: "1AAFFUB2KR3h0S0317__4aWVmvEQwDmIR2fdxsGL4cZGqiZjavby0HkZT70COXZm6XlswiDTQXSM7ir1qZX9uGoKGI9FbI7dSiquLv9-shzV8qOb126UToXHiKfe_oDFRzCg" | |
}.to_json, | |
{ | |
Authorization: "Bearer #{user.dropbox_access_token}", | |
content_type: :json, | |
accept: :json | |
} | |
) | |
# The JSON that comes back | |
# { | |
# "entries": [{ | |
# ".tag": "file", | |
# "name": "City Hall Spire.jpg", | |
# "path_lower": "/city hall spire.jpg", | |
# "id": "id:dViXaZY8BNAAAAAAAAAAAQ", | |
# "client_modified": "2013-02-14T22:31:44Z", | |
# "server_modified": "2015-12-28T12:02:08Z", | |
# "rev": "354177ea46", | |
# "size": 231284 | |
# }, { | |
# ".tag": "deleted", | |
# "name": "untitled folder", | |
# "path_lower": "/untitled folder" | |
# }, { | |
# ".tag": "folder", | |
# "name": "star labs", | |
# "path_lower": "/star labs", | |
# "id": "id:0B5Ioz5YTMAAAAAAAAAAAQ" | |
# }], | |
# "cursor": "1AAELiljFwSJyRyy2dINb9slCzsG9XJbi3OzFF5YlpLco2kpK1wsEGmlUZ5o8JSpF03ysIKEVdo3sqjoVKC0g1bRHBgUGmp6Yg2tF2bsbP54-rfDaYuXS9no0hS7Jee4YEsA", | |
# "has_more": false | |
# } | |
# So it appears that the response JSON is missing the `/star labs/DSC00845.jpg` image. | |
# Now lets do the same call with the cursor set to the one I retrieved from /list_folder with the recursive option set | |
resp = RestClient.post( | |
"https://api.dropboxapi.com/2/files/list_folder/continue", | |
{ | |
cursor: "1AAH9pUapmbJLMwj9jgrhh-IGNGsqRqK_wjRlo8dsSLNYpKCvcN59DamCACNTKETBxeLKqjmcEUqB-t7gWNLTPaPr9c0-jB9WlzvnMkVT0MJihx9_G_vlJrMmRvEcvIJqZTo" | |
}.to_json, | |
{ | |
Authorization: "Bearer #{user.dropbox_access_token}", | |
content_type: :json, | |
accept: :json | |
} | |
) | |
# Response JSON comes back with the DSC00845.jpg image as expected. | |
# { | |
# "entries": [{ | |
# ".tag": "file", | |
# "name": "City Hall Spire.jpg", | |
# "path_lower": "/city hall spire.jpg", | |
# "id": "id:dViXaZY8BNAAAAAAAAAAAQ", | |
# "client_modified": "2013-02-14T22:31:44Z", | |
# "server_modified": "2015-12-28T12:02:08Z", | |
# "rev": "354177ea46", | |
# "size": 231284 | |
# }, { | |
# ".tag": "deleted", | |
# "name": "untitled folder", | |
# "path_lower": "/untitled folder" | |
# }, { | |
# ".tag": "folder", | |
# "name": "star labs", | |
# "path_lower": "/star labs", | |
# "id": "id:0B5Ioz5YTMAAAAAAAAAAAQ" | |
# }, { | |
# ".tag": "file", | |
# "name": "DSC00845.jpg", | |
# "path_lower": "/star labs/dsc00845.jpg", | |
# "id": "id:EeVxnH_s_6AAAAAAAAAAAQ", | |
# "client_modified": "2013-06-30T17:43:27Z", | |
# "server_modified": "2015-12-28T12:02:37Z", | |
# "rev": "394177ea46", | |
# "size": 841702 | |
# }], | |
# "cursor": "1AAGDxVFtPVeWRlIk1c6dAnNhD9JlduJ73XB01pgORs3r3yzSAO7MKfBg9DMcgWRaOt646dUaD1WoU6O32aFCyYQ1K_FhPJzF4iQm-61DrwZ0roTks8aud0ihz6ObQWkxEF0", | |
# "has_more": false | |
# } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment