简体   繁体   English

在将Hammock与Tumblr API结合使用以检索喜欢项时,为什么会出现此401未经授权的错误?

[英]Why am I getting this 401 unauthorized error while using Hammock with the Tumblr API to retrieve likes?

Here is the code that I am using: 这是我正在使用的代码:

        public static void FetchXML()
        {
            _url = new Uri("http://api.tumblr.com/v2/blog/" + _username + ".tumblr.com/likes?api_key=REc3Z6l4ZYss11a8lX6KKje0X8Hsi9U77SyaPbQrOBBCGJGA6D");

            var client = new RestClient();
            client.Authority = _url.ToString();

            var request = new RestRequest();

            request.AddParameter("limit", "20");
            request.AddParameter("offset", _offset.ToString());

            var response = client.Request(request);
            var content = response.Content.ToString();
            var parsedResponse = JsonParser.FromJson(content);
        }

If I take the Uri value and paste it into my browser (using a valid Tumblr username) I'm getting the correct Json, but in my application the content of response is: 如果我采用Uri值并将其粘贴到浏览器中(使用有效的Tumblr用户名),则会得到正确的Json,但是在我的应用程序中, response的内容为:

    "{\"meta\":{\"status\":401,\"msg\":\"Unauthorized\"},\"response\":[]}"

Anyone have any idea why this is? 有人知道为什么会这样吗? According to the Tumblr API retrieving likes should only need the API key, which I am providing. 根据Tumblr API的检索,喜欢的对象只需要我提供的API密钥。

Hi you can use the below code to get the response. 嗨,您可以使用下面的代码来获取响应。

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.Method = "GET";
            request.ContentType = "Application/json";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream receive = response.GetResponseStream();
            StreamReader reader = new StreamReader(receive, Encoding.UTF8);
            string respond = reader.ReadToEnd();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 Google Calendar API 中收到 (401) 未经授权的错误 - Why am I getting a (401) Unauthorized Error in Google Calendar API 为什么我会收到未经授权的Yahoo OAuth 2.0错误(401)? - Why i am getting Yahoo OAuth 2.0 error (401) Unauthorized? 为什么我会收到 401 未经授权的响应? - Why Am I Getting 401 Unauthorized Response? 将文件字节流发送到WCF服务时,为什么会出现“ 401-未经授权”错误? - Why am I getting a “401 - Unauthorized” error when sending a file byte stream to a WCF service? 为什么我收到“远程服务器返回错误:(401) 未经授权”。 从这个代码片段? - Why am I getting 'The remote server returned an error: (401) Unauthorized.' from this code snippet? 将HttpResponseMessage与安全网址一起使用时,为什么会出现未经授权的401? - Why am I getting a 401 unauthorized when using HttpResponseMessage with a secure url? 尝试使用HttpClient检索AccesToken时出现错误 - While trying to retrieve the AccesToken using HttpClient I am getting an error 通过Intuit API访问quickBooks数据时,.NET中出现“ Unauthorized-401”错误 - Getting “Unauthorized-401” Error in .NET while accessing quickBooks data through Intuit API 我在 c# wpf 中使用 spotify api 未经授权收到错误 401 - im getting a error 401 unauthorized using the spotify api in c# wpf 出现错误:远程服务器返回错误:(401)未经授权。 ,同时将我的网站评论发布到Twitter。 使用C# - Getting error : The remote server returned an error: (401) Unauthorized. , while posting my website comments to twitter. Using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM