Last active
December 15, 2015 02:18
-
-
Save pierreant-p/5185786 to your computer and use it in GitHub Desktop.
Sketchfab folder API
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
import urllib | |
import urllib2 | |
api_token = "FF00FF" # your api token | |
## | |
# Create a new folder | |
# POST to https://api.sketchfab.com/v1/folders | |
## | |
url = "https://api.sketchfab.com/v1/folders" | |
data = urllib.urlencode({ | |
'name': 'My New Folder', # folder name | |
'desc': 'My New Folder description', # folder description | |
'items': ['8MCt8t6SyeQBuJJU57xRGKf7KCy', 'b1eScG8hB3dvInzWPUct4KoTZZz'], # list of models in the model | |
'token': api_token # your api token | |
}, True) # note the True parameter for proper list encoding | |
response = urllib2.urlopen(url, data) | |
print response | |
# sample response (returned as a json object) | |
folder = { | |
'result': { | |
'id': 1, # id of the folder | |
'user_id': '35824', # id of the folder's owner | |
'name': 'My New Folder', # name of the folder | |
'items': [ # list of models in the folder | |
'8MCt8t6SyeQBuJJU57xRGKf7KCy', | |
'b1eScG8hB3dvInzWPUct4KoTZZz' | |
], | |
'created_at': '2013-03-13 20:06:19', # date the folder was created at | |
'updated_at': '2013-03-13 20:06:19', # date the folder was last updated at | |
'slug': 'my-new-folder', # url-compatible version of the folder title | |
'desc': 'My New Folder description' # folder description | |
}, | |
'success': 'true' | |
} | |
## | |
# Get a folder details | |
# GET to https://api.sketchfab.com/v1/folders/<folder_id> | |
## | |
folder_id = 174 # folder id | |
url = "https://api.sketchfab.com/v1/folders/%s?token=%s" % (folder_id, api_token) | |
response = urllib2.urlopen(url).read() | |
print response | |
# sample response (returned as a json object) | |
folder = { | |
'result': { | |
'id': 174, | |
'user_id': '35824', | |
'name': 'My New Folder', | |
'items': [ # list of models in the folder | |
'8MCt8t6SyeQBuJJU57xRGKf7KCy', | |
'b1eScG8hB3dvInzWPUct4KoTZZz' | |
], | |
'created_at': '2013-03-13 20:06:19', # date the folder was created at | |
'updated_at': '2013-03-13 20:06:19', # date the folder was last updated at | |
'slug': 'my-folder', # url-compatible version of the folder title | |
'desc': 'My folder description' # folder description | |
}, | |
'success': 'true' | |
} | |
## | |
# Update a folder's details | |
# POST to https://api.sketchfab.com/v1/folders/<folder_id> | |
## | |
folder_id = 174 # folder id | |
url = "https://api.sketchfab.com/v1/folders/%s" % (folder_id,) | |
data = urllib.urlencode({ | |
'name': 'My Updated Folder Title', | |
'desc': 'My Updated Folder description', | |
'items': ['8MCt8t6SyeQBuJJU57xRGKf7KCy', 'zdYQzx9xxVoNb8OJbR8iQf6GOK6'], | |
'token': api_token | |
}, True) | |
response = urllib2.urlopen(url, data) | |
print response | |
# sample response (returned as a json object) | |
folder = { | |
'result': { | |
'id': 174, | |
'user_id': '35824', | |
'name': 'My Updated Folder Title', | |
'items': [ | |
'8MCt8t6SyeQBuJJU57xRGKf7KCy', | |
'zdYQzx9xxVoNb8OJbR8iQf6GOK6' | |
], | |
'created_at': '2013-03-13 20:06:19', | |
'updated_at': '2013-03-13 22:06:19', | |
'slug': 'my-updated-folder-title', | |
'desc': 'My Updated Folder description' | |
}, | |
'success': 'true' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment