Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BlaayLock/f47b7fcfd3f8dbae023dd67380ab713e to your computer and use it in GitHub Desktop.
Save BlaayLock/f47b7fcfd3f8dbae023dd67380ab713e to your computer and use it in GitHub Desktop.
#~ How to upload image to imgur as a specific user
#~ https://api.imgur.com/endpoints/image#image-upload
client_id = '152n90e218cakme'
access_token ='07566baa9e20c57e71203191dde1daffc6250ad3'
#~ Get Access token from : from imgurpython import ImgurClient ;)
import urllib2
import urllib
import base64
import json
fotoalbumId='JsaDG'
def uplink(link,salbum,stitle,sdesc):
try:
f = urllib.urlopen(link)
image_data = f.read()
b64_image = base64.standard_b64encode(image_data)
#~ headers = {'Authorization': 'Client-ID ' + client_id}
headers = {'authorization': 'Bearer '+Accesstoken}
data = {'image': b64_image, 'title': stitle,'album': salbum,'description': sdesc} # create a dictionary.
request = urllib2.Request(url="https://api.imgur.com/3/upload.json", data=urllib.urlencode(data),headers=headers)
response = urllib2.urlopen(request).read()
parse = json.loads(response)
return parse['data']['link']
except Exception as e:
print e
exit() #~Turning airplane mode on via ADB
return ''
uplink('https://lh3.googleusercontent.com/HkHxA0s0XaswNlhaCZPn6h2xbhbiLjdlsykPJ2-V0IdMqgCOz3rjubqHRYuQtJEmpg=w200-h300',fotoalbumId,'test title','test desc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment