https://imgur.com/register
https://api.imgur.com/oauth2/addclient
Lorsque vous soumettez, «Client ID» et «Client secret» seront émis. Cependant, pour les téléchargements anonymes, tout ce dont vous avez besoin est un «ID client».
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