我正在使用 C# 在我的应用程序中实现 youtube 登录,我想知道为什么每当我请求访问令牌时它都会不断返回“错误请求”消息 我有客户端 ID、客户端密码、重定向 URI 等可供访问,但它一直向我返回错误的请求。 请告诉我我的代码有什么问题
try
{
string clientId = "~~~";
string clientSecret = "~~~";
string redirectUri = "urn:ietf:wg:oauth:2.0:oob";
string tokenEndpoint = "https://oauth2.googleapis.com/token";
HttpClient client = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "authorization_code"),
new KeyValuePair<string, string>("code", code),
new KeyValuePair<string, string>("redirect_uri", redirectUri),
new KeyValuePair<string, string>("response_type", "token"),
new KeyValuePair<string, string>("scope", "https://www.googleapis.com/auth/youtube"),
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret)
});
HttpResponseMessage response = await client.PostAsync(tokenEndpoint, content);
第一个问题,您不能使用 urn:ietf:wg:oauth:2.0:oob 作为重定向 uri,您需要使用 localhost
其次帖子正文应该采用查询字符串的形式
code=[REDACTED]&client_id=[REDACTED]&client_secret=[REDACTED]&redirect_uri=https:\\127.0.0.1&grant_type=authorization_code
第三为什么不使用 google .net 客户端库?