Я не понимаю, что случилось с этой функцией, чтобы получить мой authkey? Я получаю эту ошибку под названием «invalid_request», есть ли у кого-нибудь идеи? Кажется, что он не понимает мою просьбу?Oauth2 YouTube «error»: «invalid_request»
// INNK
public partial class OAuth : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string _clientID = HttpUtility.UrlEncode("***********");
string _clientSecret = HttpUtility.UrlEncode("******");
string _redirectUri = "urn:ietf:wg:oauth:2.0:oob";
string _code = HttpUtility.UrlEncode("token");
string url = "code=" + _code + "&client_id=" + _clientID + "&client_secret=" + _clientSecret + "&redirect_uri=" + _redirectUri + "&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer";
TcpClient client = new TcpClient("accounts.google.com", 443);
Stream netStream = client.GetStream();
SslStream sslStream = new SslStream(netStream);
sslStream.AuthenticateAsClient("accounts.google.com");
{
byte[] contentAsBytes = Encoding.ASCII.GetBytes(url.ToString());
StringBuilder msg = new StringBuilder();
msg.AppendLine("POST /o/oauth2/token HTTP/1.1");
msg.AppendLine("Host: accounts.google.com");
msg.AppendLine("Content-Type: application/x-www-form-urlencoded");
msg.AppendLine("Content-Length: " + contentAsBytes.Length.ToString());
msg.AppendLine("");
Debug.WriteLine("Request");
Debug.WriteLine(msg.ToString());
Debug.WriteLine(url.ToString());
byte[] headerAsBytes = Encoding.ASCII.GetBytes(msg.ToString());
sslStream.Write(headerAsBytes);
sslStream.Write(contentAsBytes);
}
Debug.WriteLine("Response");
StreamReader reader = new StreamReader(sslStream);
while (true)
{ // Print the response line by line to the debug stream for inspection.
string line = reader.ReadLine();
if (line == null)
break;
Debug.WriteLine(line);
}
}
}