2012-05-15 19 views
0

你好,我试图使用谷歌日历API。我无法获取访问令牌。C#:无法获取Accesstoken。谷歌日历API

这是我目前使用的代码:

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文档是在这里:https://developers.google.com/accounts/docs/OAuth2InstalledApp

我经常收到HTTP错误请求400错误。

我试图在这一问题给出的解决方案,但它不工作之一: Google Calendar API - Bad Request (400) Trying To Swap Code For Access Token

有人请指出我在做什么错在这里?

回答