imgur.com - Imgur的官方網站,在這里你可以注冊并管理自己的圖像上傳和共享。
2、Imgur幫助中心 - 提供有關Imgur網站、API和移動應用的詳細信息,以幫助用戶更好地使用Imgur。
3、Imgur官方博客 - Imgur最新消息和聯系Imgur社區的最佳方法。
4、Imgur API文檔 - Imgur開發者可以在這里找到API文檔,以便開發本地應用和工具。
示例代碼:
// 使用Python代碼上傳圖像到Imgur圖床
import requests
import json
client_id = "YOUR_CLIENT_ID" # 在Imgur注冊應用程序后獲取客戶端ID和客戶端密鑰
client_secret = "YOUR_CLIENT_SECET"
# 獲取Access Token
def get_access_token():
url = "https://api.imgur.com/oauth2/token"
data = {
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "client_credentials"
}
headers = {"content-type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=data, headers=headers)
access_token = json.loads(response.text)['access_token']
return access_token
# 上傳圖像
def upload_image(image_path):
url = "https://api.imgur.com/3/image"
headers = {"Authorization": "Bearer {}".format(get_access_token())}
with open(image_path, "rb") as image_file:
payload = {
"image": image_file.read(),
"type": "file"
}
response = requests.post(url, data=payload, headers=headers)
link = json.loads(response.text)['data']['link']
return link
# 示例
if __name__ == '__main__':
image_path = "test.jpg"
link = upload_image(image_path)
print("Imgur鏈接:{}".format(link))