【问题标题】:Unauthorized error when trying to get Nest Access Token尝试获取 Nest 访问令牌时出现未经授权的错误
【发布时间】:2015-06-12 17:56:48
【问题描述】:

直到几天前一切正常,我在尝试获取 Nest 访问令牌时开始收到未经授权的错误。我已经仔细检查过,客户端 ID 和客户端密码都是正确的。关于可能导致它的任何想法?

HttpWebRequest request = WebRequest.CreateHttp("https://api.home.nest.com/oauth2/access_token?");
var token = await request.GetValueFromRequest<NestToken>(string.Format(
    "client_id={0}&code={1}&client_secret={2}&grant_type=authorization_code",
                CLIENTID,
                code.Value,
                CLIENTSECRET));

public async static Task<T> GetValueFromRequest<T>(this HttpWebRequest request, string postData = null)
{
    T returnValue = default(T);

    if (!string.IsNullOrEmpty(postData))
    {
        byte[] requestBytes = Encoding.UTF8.GetBytes(postData);

        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";

        using (var postStream = await request.GetRequestStreamAsync())
        {
            await postStream.WriteAsync(requestBytes, 0, requestBytes.Length);
        }
    }
    else
    {
        request.Method = "GET";
    }

    var response = await request.GetResponseAsync();

    if (response != null)
    {
        using (var receiveStream = response.GetResponseStream())
        {
            using (var reader = new StreamReader(receiveStream))
            {
                var json = await reader.ReadToEndAsync();
                    var serializer = new DataContractJsonSerializer(typeof(T));

                using (var tempStream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                {
                    return (T)serializer.ReadObject(tempStream);
                }
            }
        }
    }

    return returnValue;
}

【问题讨论】:

  • 嗨 Rohit,我一直在围绕 Nest REST API 开发一个 .NET 包装器。我没有看到太多人使用 .NET,所以我想我会分享我的工作:github.com/mitchdenny/birdhouse 我正在使用 Newtonsoft.Json 包进行 JSON 序列化/反序列化,它似乎工作正常,虽然在这个听起来好像是 Nest 方面的一个小故障。
  • 很酷,没有意识到这存在。我一定会试一试的!

标签: c# oauth-2.0 nest-api


【解决方案1】:

虽然我无法提供答案,但我可以确认在同一时间段内我的 iOS 应用正在发生同样的事情。

在 chrome 中使用 postman 获取我的 url 和 post 值可以正常工作。 Alamofire 抛出错误 401,就像你的原生 swift 测试代码一样。

Nest 是否改变了他们的 https 协商?

【讨论】:

  • 我的 OS X 应用程序也有这个功能。
  • 到目前为止,我一直无法找到 Nest 方面的更改记录,但看起来他们确实改变了一些东西。我正在基于他们已经实施新架构以支持他们转向更低的报价等。
  • 截至今天,它似乎对我来说再次正常工作,没有任何变化。
  • 好消息罗希特。我个人认为 Nest 应该解释发生了什么。这影响了应用的销售和声誉,因为它被视为应用故障,而不是服务提供商问题。
  • Nest 已经确认了他们最终的错误“现在已修复”,但没有详细信息和根本原因。
【解决方案2】:

这原来是因为 Nest 端的一个故障后来被修复了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 2016-06-02
    • 2012-06-24
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多