2013-02-15 66 views
0
var values = new NameValueCollection 
{ 
    { "key", "key_edited_for_security" }, 
    { "image", Convert.ToBase64String(ms.ToArray()) } 
}; 

byte[] response = w.UploadValues("https://api.imgur.com/2/upload.xml", values); 

這工作得很好,關鍵是從另一個計算器後,有人創造了一個幾年前,(Uploading to imgur.com),我註冊我的應用程序在imgur here但是當我使用我的客戶ID或客戶端密鑰ID我得到錯誤400(壞請求)。使用我的密鑰上傳到imgur的問題?

+0

從未張貼在公共場所你的API密鑰!關鍵編輯! – 2013-02-15 22:44:49

+0

這不是我的,它來自於我鏈接到的其他問題,它是第一個出現在谷歌上的,因此它幾乎不是私人的。 – 2013-02-15 22:46:09

+0

也許他們需要時間將你添加到db – sed 2013-02-15 23:06:11

回答

0

我沒有測試上面的代碼,似乎是工作的罰款

static void Main(string[] args) 
    { 

     WebClient client = new WebClient(); 
     NameValueCollection values = new NameValueCollection(); 
     values["image"] = Convert.ToBase64String(File.ReadAllBytes(@"C:\test.jpg")); 
     values["key"] = "the_key"; 
     byte[] responseBytes = client.UploadValues("https://api.imgur.com/2/upload.xml", values); 
     string response = Encoding.Default.GetString(responseBytes); 
     client.Dispose(); 
     /* Content of response 
     <?xml version="1.0" encoding="utf-8"?> 
     <upload><image><name/><title/><caption/><hash>E63BcFm</hash><deletehash>zWO2xnca2co0VcB</deletehash><datetime>2013-02-15 23:15:45</datetime><type>image/jpeg</type><animated>false</animated><width>677</width><height>342</height><size>29513</size><views>0</views><bandwidth>0</bandwidth></image><links><original>http://i.imgur.com/E63BcFm.jpg</original><imgur_page>http://imgur.com/E63BcFm</imgur_page><delete_page>http://imgur.com/delete/zWO2xnca2co0VcB</delete_page><small_square>http://i.imgur.com/E63BcFms.jpg</small_square><large_thumbnail>http://i.imgur.com/E63BcFml.jpg</large_thumbnail></links></upload> 
     */ 
    } 
+0

使用哪個鍵?正如我所說的那樣,它與問題中的原始密鑰一起工作,但使用它我不會。 – 2013-02-15 23:22:10

+0

我用我自己的鑰匙!工作得很好! – 2013-02-16 04:14:51

+0

在他們的網站上找到匿名密鑰,感謝您的幫助。 – 2013-02-21 22:41:01