如何上传到imgur用户的帐户 [英] How do I upload to an imgur user's account
问题描述
我能够上传匿名图像使用API像这样imgur:
I am able to upload anonymous images to imgur using the api like this:
public static void UploadImage()
{
Image image = GetImage();
string base64 = Util.ImageToBase64(image);
using (WebClient client = new WebClient())
{
client.Headers.Add("Authorization", "Client-ID " + clientID);
NameValueCollection data = new NameValueCollection();
data["image"] = base64;
data["type"] = "base64";
byte[] responsePayload = client.UploadValues("https://api.imgur.com/3/image/", "POST", data);
string response = Encoding.ASCII.GetString(responsePayload);
}
}
它上传到一个完全随机的网址。我找不到任何文件,这表明如何做到这一点,但有可能将图像上传到的用户的帐户,它显示在其上传的图片?
It's uploading to a completely random url. I couldn't find any documentation which showed how to do this, but is it possible to upload an image to a user's account so that it shows in their uploaded images?
推荐答案
我想通了。相反,发送客户ID
头,你需要发送一个旗手
标题,带有令牌您使用imgur的的OAuth 2 API 收到。这使您可以发表图片到用户的账户,而在此之前,我只providewd委托人身份证,这让我张贴的匿名图像。代码如下:
I figured it out. Instead of sending a "CLIENT-ID"
header, you need to send a "BEARER"
header, with the token that you recieve by using imgur's oauth 2 api. This allows you to post images to a user's account, whereas before I only providewd the client id, which allowed me to post anonymous images. The code looks like this:
client.Headers.Add("Authorization", "BEARER " + accessToken);
这篇关于如何上传到imgur用户的帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!