使用Imgur API 3上传图片报告我不是相册的所有者

时间:2017-05-26 05:46:07

标签: c# image-uploading imgur

我创建了一个Imgur帐户,并在创建相册之前获取了我的客户ID和密钥。我的目标是在将其集成到我的应用程序之前在测试环境中编写。

以下是我到目前为止使用的代码的最终版本:

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;
    }
}

当我运行代码时,我收到的消息显示我并不显然拥有我想要的专辑。具体做法是:

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.

我曾经想过,自从我使用我的帐户登录后创建了相册,它应该可以正常工作 - 现在我错过了一些东西。非常感谢您对此的额外关注。谢谢。

安迪

0 个答案:

没有答案