I created an Imgur account and acquired my client ID and secret key before creating an album. My goal was to write in a test environment before integrating it into my application.
Below is final version of the code I have used up until now:
string base64String;
string message;
string album = "abcxyz";
using (Image image = Image.FromFile("c:\\path_to\\image.jpg"))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
base64String = Convert.ToBase64String(imageBytes);
}
}
using (var client = new WebClient())
{
string clientID = "supersecret";
client.Headers.Add("Authorization", $"Client-ID {clientID}");
System.Collections.Specialized.NameValueCollection valueCollection = new System.Collections.Specialized.NameValueCollection();
valueCollection["image"] = base64String;
valueCollection["type"] = "base64";
valueCollection["album"] = album;
try
{
byte[] response = client.UploadValues("https://api.imgur.com/3/upload", "POST", valueCollection);
message = Encoding.ASCII.GetString(response);
}
catch (Exception ex)
{
message = ex.Message;
}
}
When I run the code I get the message back that I don't apparently own the album that I'm trying to. Specifically:
error=You are not the owner of album '<album hash>', which means you can't
add images to it. For anonymous albums, use the album deletehash.
I had thought that since I created the album while logged on with my account that it should work - and now I'm missing something. Any extra eyes on this would be greatly appreciated thank you.
Andy