AccessToken for Windows 推送通知返回错误请求 400 [英] AccessToken for Windows Push Notifications returns Bad Request 400

查看:30
本文介绍了AccessToken for Windows 推送通知返回错误请求 400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙!!无法弄清楚为什么 MSDN 给出的这个简单代码不起作用....

我在 GetAccessToken() 中使用以下代码,如 这篇 MSDN 文章 获取要在 Windows 通知中使用的访问令牌,但它返回错误请求 400"

I am using the following code in GetAccessToken() as given in the this MSDN article to get the access token to be used in windows notifications, but it returns "Bad Request 400"

PACKAGE_SECURITY_IDENTIFIER、CLIENT_SECRET 是应用在 Windows 应用商店仪表板中注册时获得的值

PACKAGE_SECURITY_IDENTIFIER, CLIENT_SECRET are the values obtained when the app was registered with the Windows Store Dashboard

string urlEncodedSid = HttpUtility.UrlEncode(PACKAGE_SECURITY_IDENTIFIER);
string urlEncodedSecret = HttpUtility.UrlEncode(CLIENT_SECRET);

string body = String.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=notify.windows.com", urlEncodedSid, urlEncodedSecret);

string response;

using (WebClient client = new WebClient())
{
    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
    response = client.UploadString("https://login.live.com/accesstoken.srf", body);
}

任何帮助将不胜感激......

Any help would be highly appreciated.......

推荐答案

我找到了错误响应的原因.实际上是错误的 PACKAGE_SECURITY_IDENTIFIER 和 CLIENT_SECRET.

I found the reason for the error response. In fact it is the wrong PACKAGE_SECURITY_IDENTIFIER and CLIENT_SECRET.

请勿键入值.因为关联的 ASCII 值不同.因此,最好直接复制粘贴.

DO NOT type the values. Because associated ASCII values differ. Therefore it is always better to copy and paste directly.

您可能会通过简单的代码片段获得访问令牌.

You will probably will get the access token with the simple code snippet.

干杯

这篇关于AccessToken for Windows 推送通知返回错误请求 400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆