https://imgur.com/register
https://api.imgur.com/oauth2/addclient
--Application name: Application name --Application name: Select ʻAnonymous usage without user authorization` if you only need anonymous upload --Authorization callback URL: Not relevant for anonymous uploads. Enter an appropriate URL. --Application website (optional): Optional -Email: Appropriate email address --Description: Optional
When you submit, Client ID
and Client secret
will be issued. However, for anonymous uploads, all you need is a Client ID
.
client_id = 'YOUR CLIENT ID'
image_path = 'path/to/your/image'
import requests
headers = {
'authorization': f'Client-ID {client_id}',
}
files = {
'image': (open(image_path, 'rb')),
}
r = requests.post('https://api.imgur.com/3/upload', headers=headers, files=files)
import json
print(json.loads(r.text)['data']['link'])
image_url = 'YOUR IMAGE URL'
client_id = 'YOUR CLIENT ID'
import requests
headers = {
'authorization': f'Client-ID {client_id}',
}
files = {
'image' : requests.get(image_url).content
}
r = requests.post('https://api.imgur.com/3/upload', headers=headers, files=files)
import json
print(json.loads(r.text)['data']['link'])
Recommended Posts