importrequestsfromrequests.authimportHTTPBasicAuthendpoint='https://api.imagga.com/v1'api_key='YOUR_API_KEY'api_secret='YOUR_API_SECRET'auth=HTTPBasicAuth(api_key,api_secret)# Open the desired filewithopen('example_image.jpg','r')asimage_file:filename=image_file.name# Upload the multipart-encoded image with a POST# request to the /content endpointcontent_response=requests.post('%s/content'%endpoint,auth=auth,files={filename:image_file})# Example /content response:# {'status': 'success',# 'uploaded': [{'id': '8aa6e7f083c628407895eb55320ac5ad',# 'filename': 'example_image.jpg'}]}uploaded_files=content_response.json()['uploaded']# Get the content id of the uploaded filecontent_id=uploaded_files[0]['id']# Using the content id and the content parameter,# make a GET request to the /tagging endpoint to get# image tagstagging_query={'content':content_id}tagging_response=requests.get('%s/tagging'%endpoint,auth=auth,params=tagging_query)results=tagging_response.json()print(results)
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.