Giter VIP home page Giter VIP logo

imgur.api's Introduction

Imgur.API

Imgur.API is a .NET implementation of Imgur's API.

Build

Quality Gate Status

NuGet

Getting Started

Register Client

Register your App at https://api.imgur.com/oauth2/addclient

Creating an ApiClient

var apiClient = new ApiClient("YOUR_CLIENT_KEY");

Using OAuth

Getting an Authorization Url

The Authorization Url should be loaded in a browser, allowing the user to login to Imgur.

var apiClient = new ApiClient("YOUR_CLIENT_KEY", "YOUR_CLIENT_SECRET");
var httpClient = new HttpClient();

var oAuth2Endpoint = new OAuth2Endpoint(apiClient, httpClient);
var authUrl = oAuth2Endpoint.GetAuthorizationUrl();

Once user has logged in, they are redirected to your previously set Url. Once the token information is available and parsed create a token.

var token = new OAuth2Token
{
    AccessToken = "YOUR_TOKEN",
    RefreshToken = "YOUR_REFRESH_TOKEN",
    AccountId = YOUR_ACCOUNT_ID,
    AccountUsername = "YOUR_ACCOUNT_PASSWORD",
    ExpiresIn = YOUR_EXPIRATION,
    TokenType = "YOUR_TOKEN"
};

Then set the token on the ApiClient.

apiClient.SetOAuth2Token(token);

Continue to use the rest of the Endpoints.

var imageEndpoint = new ImageEndpoint(apiClient, httpClient);

Uploading Images & Video

Uploading Image

var apiClient = new ApiClient("YOUR_CLIENT_KEY");
var httpClient = new HttpClient();

var filePath = "PATH_TO_YOUR_IMAGE";
using var fileStream = File.OpenRead(filePath);

var imageEndpoint = new ImageEndpoint(apiClient, httpClient);
var imageUpload = await imageEndpoint.UploadImageAsync(fileStream);

Uploading Video

var apiClient = new ApiClient("YOUR_CLIENT_KEY");
var httpClient = new HttpClient();

var filePath = "PATH_TO_YOUR_IMAGE";
using var fileStream = File.OpenRead(filePath);

var imageEndpoint = new ImageEndpoint(apiClient, httpClient);
var imageUpload = await imageEndpoint.UploadVideoAsync(fileStream);

Uploading Video with Progress

var apiClient = new ApiClient("YOUR_CLIENT_KEY");
var httpClient = new HttpClient();

var uploadProgress = new Progress<int>(report);

var filePath = "PATH_TO_YOUR_IMAGE";
using var fileStream = File.OpenRead(filePath);

var imageEndpoint = new ImageEndpoint(apiClient, httpClient);
var imageUpload = await imageEndpoint.UploadVideoAsync(fileStream, progress: uploadProgress);

void report(int byteProgress)
{
    //Do something with the progress here. 
}

API Definition

Several Endpoints are available. The methods on the Endpoints match what is available at the official Imgur API at https://apidocs.imgur.com/

imgur.api's People

Contributors

damiendennehy avatar ddennehy-genesis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

imgur.api's Issues

Imgur not finding my callback.

From @smatthews1999 on March 6, 2016 22:10

Hello!

I am having a great deal of difficulty authenticating a user and was wondering if I could ask your help. Where I am stuck is Imgur is not able to find my callback endpoint. I keep getting a 400 status right after I authorize my app.

I have setup an application in Imgur with the following callback...

imgur03

I have two endpoints in a web api app that are handling the post/redirect (currently on http://localhost:34724)...

imgur04
The first endpoint "imgur", gets the authorization url and returns it to the client, which then redirects the browser to that url...

imgur01

However, as soon as I hit "Allow" I get the following...

imgur02

I am pretty new to this stuff and I have no idea why it's doing this. That being said I have used this exact same setup and flow to authenticate twitter oath and it worked great.

Any help is greatly appreciated!
Sam

Copied from original issue: DamienDennehy/Imgur.API.Docs#1

Stream support for uploading images

It would be lovely if you could add this. I only have VS2013 installed, so I can't create a PR myself...

If possible, supporting PushStreamContent would be even better, which would allow me to do things like:

using (var bmp = new Bitmap(256, 256))
using (var gfx = Graphics.FromImage(bmp))
{
    gfx.DrawString("nice library btw", SystemFonts.DefaultFont, SystemBrushes.InfoText, 0, 0);

    var imgur = new ImageEndpoint(new ImgurClient(ImgurClientId, ImgurClientSecret));
    imgur.UploadImagePushStreamAsync(new PushStreamContent((stream, _, __) =>
    {
        bmp.Save(stream, ImageFormat.Png);
    }));
}

as it stands, the library uses double the memory as I need to write the bmp to a MemoryStream, which is copied to another byte array, which is then wrapped by your library in another MemoryStream (ByteArrayContent also exists, so wrapping it in a stream isn't necessary either)

Nuget update

Hi, have you updated Nuget? I see there still 1. August 2016. :)

Image upload timeout

On uploading larger Images to Imgur, the upload will be cancelled and an error occurs.

Adding Images while creating an Album annonymously does not work. Neither does annonymously adding images. album.Link is broken as well.

Hello,

I'm using release 4.0.1, tha latest on NuGet. I uploaded several images, which is working, then I create an album like this:

album = await albumEndPoint.CreateAlbumAsync(albumname, "",
AlbumPrivacy.Hidden, AlbumLayout.Vertical, DeleteHashList[0], DeleteHashList);

DeleteHashList is a list of all image deletehashes. I get no error message but the album is empty. Also

album.Link is null for whatever reason. On the other hand:

await albumEndPoint.AddAlbumImagesAsync(album.DeleteHash, DeleteHashList);

throws an error: "You must own all the image ids to add them to album ALBUMID(not deletehash)".

Pastebin of my code: https://pastebin.com/dbbLss0g

Just tested with 5.0.0beta, didn't work either.

Greetings,
master117

Serialization bug with UploadImageUrlAsync

Encountering serialization error with the following:

                var endpoint = new ImageEndpoint(client);
                var image = await endpoint.UploadImageUrlAsync(photo.Url); // exception thrown here with known good URL
   Newtonsoft.Json.JsonReaderException was caught  
  _HResult=-2146233088
  _message=Unexpected character encountered while parsing value: {. Path 'data.error', line 1, position 18.
  HResult=-2146233088
  IsTransient=false
  Message=Unexpected character encountered while parsing value: {. Path 'data.error', line 1, position 18.
  Source=Newtonsoft.Json
  LineNumber=1
  LinePosition=18
  Path=data.error

Unable to Open Project File in VS2015

the title says it all. i am not able to open the project in Visual Studio 2015, can you please upgrade it so that users like me that runs VS2015 can open the API ? thank you

Feature request: Swagger

Would it be possible to make a swagger document of the API available?
This would really help in creating API libs for different languages/frameworks.

Thanks. :-)

v5.0.0 - Missing Endpoints.

As of the v5.0.0 release a number of endpoints have been removed from this project. This project currently supports:

  • OAuth2Endpoint
  • ImageEndpoint

The official API at https://apidocs.imgur.com supports five endpoints:

  • Account
  • Comment
  • Album
  • Gallery
  • Image

Album, Comment, Gallery, and Account will be added back in this order in future releases.
They were removed as it had been some time since the project was updated and Imgur's API seems to have drifted a bit.

The rational behind this is I'd rather a new version with limited but working features than an old version with everything only partially working.

TokenType must be of type Integer.

Hello, i'm getting an error into the lib :

An exception is threw : TokenType must be of type Integer.

Here my code ๐Ÿ‘

var client = new ImgurClient(client_id, token); var endpoint = new AccountEndpoint(client); var fav = await endpoint.GetAccountFavoritesAsync(); List<Task<models.Image>> images = new List<Task<models.Image>>();

The token.TokenType is of type String, as the constructor of OAuth2Token asks. The value is bearer.

Here the full stacktrace

at Imgur.API.JsonConverters.EpochTimeConverter.ReadJson (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue, Newtonsoft.Json.JsonSerializer serializer) [0x00011] in <afa0bc68c61a40b18a6236ca9b736858>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable (Newtonsoft.Json.JsonConverter converter, Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue) [0x00055] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x0004e] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00267] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00158] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000d9] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <2781d1b198634655944cdefb18b3309b>:0 at Imgur.API.JsonConverters.GalleryItemConverter.ReadJson (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue, Newtonsoft.Json.JsonSerializer serializer) [0x00060] in <afa0bc68c61a40b18a6236ca9b736858>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable (Newtonsoft.Json.JsonConverter converter, Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue) [0x00055] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) [0x0016f] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) [0x000dc] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0007f] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00061] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00267] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00158] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000d9] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonConverter[] converters) [0x00017] in <2781d1b198634655944cdefb18b3309b>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonConverter[] converters) [0x00000] in <2781d1b198634655944cdefb18b3309b>:0 at Imgur.API.Endpoints.Impl.EndpointBase.ProcessEndpointResponse[T] (System.Net.Http.HttpResponseMessage response) [0x001b3] in <afa0bc68c61a40b18a6236ca9b736858>:0 at Imgur.API.Endpoints.Impl.EndpointBase.SendRequestAsync[T] (System.Net.Http.HttpRequestMessage message) [0x000dd] in <afa0bc68c61a40b18a6236ca9b736858>:0 at Imgur.API.Endpoints.Impl.AccountEndpoint.GetAccountFavoritesAsync () [0x000d9] in <afa0bc68c61a40b18a6236ca9b736858>:0 at Epicture2019.services.ImgurService.getFavoritesImages () [0x0005b] in C:\Users\Tom\Documents\DEV_epicture_2019\Epicture2019\Epicture2019\services\ImgurService.cs:121

Thanks.

UploadImage misses the name parameter

The API docs refers to an optional name parameter

Image Upload

Key Required Description
name optional The name of the file, this is automatically detected if uploading a file with a POST and multipart / form-data

This parameter is missing in the endpoint methods

public interface IImageEndpoint : IEndpoint
{
    Task<IImage> UploadImageBinaryAsync(
        byte[] image, 
        string albumId = null, 
        string title = null,
        string description = null);

    Task<IImage> UploadImageStreamAsync(
        Stream image, 
        string albumId = null, 
        string title = null,
        string description = null, 
        IProgress<int> progressBytes = null, 
        int progressBufferSize = 4096);

    Task<IImage> UploadImageUrlAsync(
        string image, 
        string albumId = null, 
        string title = null,
        string description = null);
}

SubReddit gallery

Hi, I am getting this error, when I am using endpoint subreddit gallery, here's my code :
var client = new ImgurClient("ID .......");
var endpoint = new GalleryEndpoint(client);
var images = await endpoint.GetSubredditGalleryAsync("aww");
Error :

System.ArgumentException: The value "Imgur.API.Models.Impl.GalleryAlbum" is not of type "Imgur.API.Models.Impl.GalleryImage" and cannot be used in this generic collection.
Parameter name: value
   at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
   at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonConverter[] converters)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
   at Imgur.API.Endpoints.Impl.EndpointBase.ProcessEndpointResponse[T](HttpResponseMessage response)
   at Imgur.API.Endpoints.Impl.EndpointBase.<SendRequestAsync>d__13`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Imgur.API.Endpoints.Impl.GalleryEndpoint.<GetSubredditGalleryAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Test_app.MainPage.<GetImage>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Test_app.MainPage.<button_Click>d__2.MoveNext()}	System.ArgumentException

Upload Image Progress

For the IImageEndpoint, there could be an event (UploadProgressChanged) added, that triggers everytime there is progress on the upload. (eventual Parameters: int ProgressPercentage).
Would be nice to see this in the future, especially useful for uploads with huge Images and low Bandwidth.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.