gpt4 book ai didi

c# - 在 C# 中通过 Imgur API 匿名获取图像信息

转载 作者:太空狗 更新时间:2023-10-29 20:34:02 27 4
gpt4 key购买 nike

我正在尝试通过 C# 通过 Imgur 第 3 版 API 匿名获取图像数据(如图像大小)。他们的文档说明

The API requires each client to use OAuth 2 authentication. This means you'll have to register your application, and generate an access_code if you'd like to log in as a user.

For public read-only and anonymous resources, such as getting image info, looking up user comments, etc. all you need to do is send an authorization header with your client_id in your requests. This also works if you'd like to upload images anonymously (without the image being tied to an account), or if you'd like to create an anonymous album. This lets us know which application is accessing the API.

Authorization: Client-ID YOUR_CLIENT_ID

所以我将 Client-ID 作为 header 添加到我的 HttpWebRequest。下面是我的代码。

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/image/id/8ABRUYt");
webRequest.Headers.Add("Authorization", "Client-ID XXXXX");
Stream response = webRequest.GetResponse().GetResponseStream();
StreamReader reader = new StreamReader(response);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
response.Close();

我收到 404 错误,但该图像显然存在 -> http://imgur.com/8ABRUYt (银河酒吧的图片)。我做错了什么吗?

最佳答案

你的第一行应该是

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/image/8ABRUYt");

正确的 url 是“https://api.imgur.com/3/image/ {id}” - {id} 是您的照片 ID。

你的帖子帮助我开始简单地查看来自 imgur 的图片!我会投票给你,但这需要 15 个声望 :( 如果可以的话,我一定会代表你 :)

关于c# - 在 C# 中通过 Imgur API 匿名获取图像信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17140364/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com