Anonymous upload of images using Imgur API (using Python)

Register as a user

https://imgur.com/register

Create application

https://api.imgur.com/oauth2/addclient スクリーンショット 2019-12-08 0.16.24.png

--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.

Post

Upload local images

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'])

Upload images already on the web

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

Anonymous upload of images using Imgur API (using Python)
[WP REST API v2] Upload images in Python
Upload JPG file using Google Drive API in Python
Try projective transformation of images using OpenCV with Python
[Question] About API conversion of chat bot using Python
[Python] Using Line API [1st Creation of Beauty Bot]
Save images using python3 requests
Upload videos using YouTube API
python: Basics of using scikit-learn ①
Faster loading of Python images
Collect large numbers of images using Bing's image search API
[Python] I tried collecting data using the API of wikipedia
Pixel manipulation of images in Python
Data acquisition using python googlemap api
[Python3] Google translate google translate without using api
Try using Pleasant's API (python / FastAPI)
Generating multilingual text images using Python
Implementation of desktop notifications using Python
Try using Python argparse's action API
Run Ansible from Python using API
Implementation of CRUD using REST API with Python + Django Rest framework + igGrid
Download images using requests
Example of using lambda
Save images using python3 requests
Aligning scanned images of animated video paper using OpenCV and Python
Regularly upload files to Google Drive using the Google Drive API in Python
Python: Basics of image recognition using CNN
Mouse operation using Windows API in Python
[Python] Extension using inheritance of matplotlib (NavigationToolbar2TK)
Automatic collection of stock prices using python
About building GUI using TKinter of Python
Try using the Wunderlist API in Python
(Bad) practice of using this in Python
Python: Application of image recognition using CNN
Tweet using the Twitter API in Python
Get Youtube data in Python using Youtube Data API
Development and deployment of REST API in Python using Falcon Web Framework
Transcription of images with GCP's Vision API
Study on Tokyo Rent Using Python (3-1 of 3)
Get images of great find / 47 sites using Python (1/2: until target list creation)
Detect Japanese characters from images using Google's Cloud Vision API in Python
Creating Google Spreadsheet using Python / Google Data API
Get rid of DICOM images in Python
Upload images to Google Drive with Python
Awareness of using Aurora Severless Data API
Meaning of using DI framework in Python
Let Python measure the average score of a page using the PageSpeed Insights API
[Python] Automatically totals the total number of articles posted by Qiita using the API
Reconstruction of moving images by Autoencoder using 3D-CNN
Time variation analysis of black holes using python
Upload a large number of images to Wordpress
Receive websocket of kabu station ® API in Python
[Python] Get all comments using Youtube Data API
Try using the BitFlyer Ligntning API in Python
Get image URL using Flickr API in Python
[Python] Takes representative values ​​of multiple images [Numpy]
Introduction of Python Imaging Library (PIL) using HomeBrew
Getting rid of DICOM images in Python Part 2
Manipulate objects using Blender 2.8's low-level Python API
Load images from URLs using Pillow in Python 3
Find the geometric mean of n! Using Python
Upload images to S3 with GUI using tkinter
Try using kabu station API of kabu.com Securities