Created
January 19, 2014 19:41
-
-
Save andymeneely/8509982 to your computer and use it in GitHub Desktop.
Using The Game Crafter API with Python
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 requests #Found at python-requests.org/ | |
url="https://www.thegamecrafter.com/api" | |
api_key_id = '' #Replace with yours | |
username = '' #Replace with yours | |
password = '' #Replace with yours | |
#Get a Session | |
params = {'api_key_id': api_key_id, 'username' : username, 'password': password} | |
response = requests.post(url + "/session", params=params) | |
if response.status_code==200: | |
print("----Status code OK!----") | |
print("---Get a session---") | |
print(response.json()) | |
print("-------------------") | |
session = response.json()['result'] | |
# Fetch my account info | |
params = {'session_id': session['id']} | |
response = requests.get(url + "/user/" + session['user_id'], params=params) | |
print("---Get account info---") | |
print(response.json()) | |
print("----------------------") | |
user = response.json()['result'] | |
root_folder_id = user['root_folder_id'] | |
# Upload a file | |
params = { | |
'name': 'example.png', | |
'folder_id': root_folder_id, | |
'session_id': session['id'] | |
} | |
files = { 'file': open('example.png','rb') } | |
response = requests.post(url + "/file", params=params, files=files) | |
print("---Upload response---") | |
print(response.json()) | |
print("---------------------") | |
# Search Games | |
params = { | |
'q' : 'Steampunk', | |
'session_id': session['id'] #optional | |
} | |
response = requests.get(url + "/game", params=params) | |
print("----- Results -----") | |
print(response) | |
print("------ Done! -------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment