Google oauth2.0,缺少必需的参数:grant_type
Google oauth2.0, required parameter is missing: grant_type
我遵循谷歌文档为我的公司桌面应用程序制作"登录谷歌",文档链接:https://developers.google.com/identity/protocols/OAuth2InstalledApp
问题是,当我发送检索access_token的post请求时,我总是收到这个错误:
"error":"invalid_request"
"error_description":"缺少必需参数:grant_type"
我确实在谷歌上搜索了几天,但不知道发生了什么。如果这是一个愚蠢的问题,请原谅,我对http一无所知。
这是我的密码。在我的代码中,我使用来自以下链接的库:http://www.codeproject.com/Articles/66625/A-Fully-Featured-Windows-HTTP-Wrapper-in-C
#include "RegExp.h"
#include "StringProcess.h"
#include "WinHttpClient.h"
#include <iostream>
using namespace std;
void main(void)
{
WinHttpClient client(L"https://accounts.google.com/o/oauth2/token");
//data of post request
string data = "";
data += "code=";
string code = "some_code";
data += code;
data += "&client_id=";
string client_id = "my_app_id";
data += client_id;
data += "&client_secret=";
string client_secret = "my_app_secret";
data += client_secret;
data += "&redirect_uri";
string redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
data += redirect_uri;
data += "&grant_type=";
string grant_type = "authorization_code";
data += grant_type;
client.SetAdditionalDataToSend((BYTE *)data.c_str(), data.size());
//header of post request
wstring headers = L"Content-Length: ";
headers += L"rnContent-Type: application/x-www-form-urlencodedrn";
wchar_t szHeaders[MAX_PATH * 10] = L"";
swprintf_s(szHeaders, MAX_PATH * 10, headers.c_str(), data.size());
client.SetAdditionalRequestHeaders(szHeaders);
//send request and print response
client.SendHttpRequest(L"POST");
wstring httpResponseHeader = client.GetResponseHeader();
wstring httpResponseContent = client.GetResponseContent();
char content[10000];
sprintf(content, "%ls", httpResponseContent.c_str() );
char header[10000];
sprintf(header, "%ls", httpResponseHeader.c_str());
cout << header << endl;
cout << content << endl;
system("pause");
}
非常感谢
您的redirect_uri必须是一个真实的uri,并且必须匹配if;redirect_uri";参数包含在第4.1.1节(RFC 6749)中描述的授权请求中,并且它们的值必须相同。uri必须类似scheme:[//[user:password@]host[:port]][/]path
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用Luacneneneba API正确读取字符串和表参数
- 在派生函数中指定void*参数
- 视图中的参数推导失败:take_while
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- 使用指向成员的指针将成员函数作为参数传递
- 没有名称的C++模板参数
- 如何将enable-if与模板参数和参数包一起使用