0

我正在使用 google auth 从 Windows Store App 访问 GMail。我得到了成功的授权码,现在我正在尝试将其换成访问码。我按照 Google Gide 中针对已安装应用程序的描述发送了 POST 查询:https ://developers.google.com/accounts/docs/OAuth2InstalledApp 。feedler 捕获了我的 POST 查询:

POST https://accounts.google.com/o/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: accounts.google.com
Content-Length: 193
Expect: 100-continue
Connection: Keep-Alive

code=4/_ynXWYzGSols1p7lzuVBc59iGhgo& client_id={my client_id obtained during application registration}   &     client_secret={ my client secret obtained during application registration encoded by Uri.EscapeDataString()}& redirect_uri={ urn:ietf:wg:oauth:2.0:oobencoded by Uri.EscapeDataString()} & grant_type=authorization_code

服务器返回“(400)错误请求”。我的请求有什么问题?

4

1 回答 1

1

不要诉诸Uri.EscapeDataString()价值观。如果您查看链接到的页面上的示例,它们也不会被转义。

这是我正在使用的代码片段:

var form = new Dictionary<string, string>
    {
        {"code", authenticationCode},
        {"client_id", Keys.ClientId},
        {"client_secret", Keys.ClientSecret},
        {"redirect_uri", "urn:ietf:wg:oauth:2.0:oob"},
        {"grant_type", "authorization_code"},
    };
var content = new FormUrlEncodedContent(form);

var client = new HttpClient();
var response = await client.PostAsync("https://accounts.google.com/o/oauth2/token", content);
var json = await response.Content.ReadAsStringAsync();
于 2013-04-18T04:42:37.017 回答