NickeManarin/ScreenToGif · error · UploadException

It was not possible to get the authorization to upload to Im

Error message

It was not possible to get the authorization to upload to Imgur.

What it means

Imgur.UploadFileAsync throws UploadException before building the HTTP request when IsAuthorized(imgurPreset) returns false. IsAuthorized is false when the preset has no RefreshToken, or when the access token has expired AND RefreshToken() fails. This is a precondition check, not a network response error — the upload HTTP call is never made.

Source

Thrown at ScreenToGif/Cloud/Imgur.cs:32

using ScreenToGif.ViewModel.UploadPresets.Imgur;
using ScreenToGif.Windows.Other;

namespace ScreenToGif.Cloud;

public class Imgur : IUploader
{
    public async Task<IHistory> UploadFileAsync(IUploadPreset preset, string path, CancellationToken cancellationToken, IProgress<double> progressCallback = null)
    {
        if (preset is not ImgurPreset imgurPreset)
            throw new Exception("Imgur preset is null.");

        var args = new Dictionary<string, string>();
        var headers = new NameValueCollection();

        if (!preset.IsAnonymous)
        {
            if (!await IsAuthorized(imgurPreset))
                throw new UploadException("It was not possible to get the authorization to upload to Imgur.");

            headers.Add("Authorization", "Bearer " + imgurPreset.AccessToken);

            if (imgurPreset.UploadToAlbum)
            {
                var album = string.IsNullOrWhiteSpace(imgurPreset.SelectedAlbum) || imgurPreset.SelectedAlbum == "♥♦♣♠" ?
                    await AskForAlbum(imgurPreset) : imgurPreset.SelectedAlbum;

                if (!string.IsNullOrEmpty(album))
                    args.Add("album", album);
            }
        }
        else
        {
            headers.Add("Authorization", "Client-ID " + Secret.ImgurId);
        }

        if (cancellationToken.IsCancellationRequested)

View on GitHub (pinned to a4d0a67c21)

Solutions

  1. Re-run the Imgur authorization flow (GetAuthorizationAdress) to obtain a fresh access + refresh token.
  2. Check the user's network/proxy can reach https://api.imgur.com/oauth2/token.
  3. If upload is optional, fall back to anonymous upload by setting preset.IsAnonymous = true.
  4. Verify the system clock — a skewed clock forces ExpiryDate to be treated as expired on every call.

Example fix

// before
if (!await IsAuthorized(imgurPreset))
    throw new UploadException("It was not possible to get the authorization to upload to Imgur.");

// after
if (!await IsAuthorized(imgurPreset))
    throw new UploadException("It was not possible to get the authorization to upload to Imgur. Please re-authorize the Imgur account.")
    {
        HelpLink = Imgur.GetAuthorizationAdress()
    };
Defensive patterns

Strategy: validation

Validate before calling

// Verify Imgur authorization before offering upload
if (!imgurPreset.IsAnonymous)
{
    if (string.IsNullOrWhiteSpace(imgurPreset.RefreshToken))
        // prompt user to authorize
    else if (await Imgur.IsAuthorized(imgurPreset) == false)
        // prompt re-authorization with Imgur.GetAuthorizationAdress()
}

Type guard

bool HasValidImgurAuth(ImgurPreset p) => p.IsAnonymous || (!string.IsNullOrWhiteSpace(p.RefreshToken) && DateTime.UtcNow <= p.ExpiryDate);

Try / catch

try { await uploader.UploadFileAsync(preset, path, token); }
catch (UploadException ex) when (ex.Message.Contains("authorization"))
{
    // re-run OAuth flow, then retry once
}

Prevention

When it happens

Trigger: preset.IsAnonymous == false AND (imgurPreset.RefreshToken is null/whitespace OR RefreshToken(preset) returned false). RefreshToken posts to api.imgur.com/oauth2/token and parses access_token; any non-200 or missing field makes it return false.

Common situations: User never finished the OAuth flow; user revoked the app at imgur.com/settings/apps; access token expired (ExpiryDate passed) and the refresh token was also invalidated by a password change or revocation; network/proxy blocked the token endpoint; Imgur OAuth2 endpoint outage.

Related errors


AI-assisted analysis of NickeManarin/ScreenToGif@a4d0a67c21 (2026-08-13). Data as JSON: /api/errors/0ccdc8fb0535adc0. Report an issue: GitHub.