Skip to content

Instantly share code, notes, and snippets.

Last active August 17, 2022 08:07
What would you like to do?
Post to imgur using oauth (api v3) on a static (no server) site
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>imgur oauth</title>
<script src=""></script>
$(function () {
var extractToken = function(hash) {
var match = hash.match(/access_token=(\w+)/);
return !!match && match[1];
var $post = $('.post');
var $msg = $('.hidden');
var $img = $('img');
$ {
localStorage.doUpload = true;
localStorage.imageBase64 = $img.attr('src').replace(/.*,/, '');
var token = extractToken(document.location.hash);
if (token && JSON.parse(localStorage.doUpload)) {
localStorage.doUpload = false;
url: '',
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
Accept: 'application/json'
data: {
image: localStorage.imageBase64,
type: 'base64'
success: function(result) {
var id =;
window.location = '' + id;
.hidden {
display: none;
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">
<a class="post" href="">
Post image to imgur
<div class="hidden">
<p>Posting to imgur...</p>
Copy link

mahye82 commented Oct 11, 2018

What is the redirect/callback URL you're using for this app in the Imgur settings?

Copy link

one of imgur api developer.

Copy link

it dosent work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment