C#:无法获取Accesstoken。谷歌日历API
你好,我正在尝试使用谷歌日历API。我无法获取访问令牌 以下是我当前使用的代码:C#:无法获取Accesstoken。谷歌日历API,c#,.net,google-api,oauth-2.0,C#,.net,Google Api,Oauth 2.0,你好,我正在尝试使用谷歌日历API。我无法获取访问令牌 以下是我当前使用的代码: private string ObtainAccessToken(string code) { string content = "code=" + code + "&" + "client_id=1016429729591.apps.googleusercontent.com&am
private string ObtainAccessToken(string code)
{
string content =
"code=" + code + "&" +
"client_id=1016429729591.apps.googleusercontent.com&"+
"client_secret={MySecret}&" +
"redirect_uri=urn:ietf:wg:oauth:2.0:oob&" +
"grant_type=authorization_code";//authorization_code";
Google.Apis.Authentication.HttpRequestFactory
factory = new Google.Apis.Authentication.HttpRequestFactory();
HttpWebRequest req = factory.Create(new Uri("https://accounts.google.com/o/oauth2/token?"+content), "POST");
byte[] data = Google.Apis.Utilities.EncodeStringToUtf8(content);
req.ContentLength = data.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.GetRequestStream().Write(data, 0, data.Length);
req.GetResponse();
}
下面是api文档:
我经常收到HTTP错误请求400错误
我尝试过这个问题中给出的解决方案,但也不起作用:
有人能指出我做错了什么吗?请检查此示例:
它是一个命令行应用程序,使用OAuth 2.0来授权任务API请求,应该很容易将其改编为使用日历API