使用 pyimgur 上传图像到 imgur,使用图像 link

Uploading image using pyimgur to imgur, using images link

我有兴趣将图像上传到 imgur API。在文档中上传图片

import pyimgur

CLIENT_ID = "Your_applications_client_id"
PATH = "A Filepath to an image on your computer"

im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(PATH, title="Uploaded with PyImgur")
print(uploaded_image.title)
print(uploaded_image.date)
print(uploaded_image.url)
print(uploaded_image.link)

我很好奇是否有人知道如何不使用路径(将图像保存在本地),而是将图像 link 上传到 imgur。我觉得它存在是因为在 GUI 网站上你可以输入图片 link 然后可以上传。

感谢您的帮助。

Imgur.upload_image() 方法接受一个 url 参数,只需将要添加的图像的 URL 传递给它即可:

uploaded_image = im.upload_image(url=URL_OF_IMAGE, title="Uploaded with PyImgur")

您必须提供路径或 URL,但不能同时提供。

查看 upload_image() documentation 它接受的所有参数:

Upload the image at either path or url.

  • path – The path to the image you want to upload.
  • url – The url to the image you want to upload.