您可以使用以下请求网址来生成访问令牌,
String URL = "https://outpost.mapmyindia.com/api/security/oauth/token?grant_type=client_credentials&client_id="+clientid+"&client_secret="+clientsecret;
并且,在 POST 方法中添加以下标头,
(“接受”,“应用程序/json”)
(“内容类型”,“application/x-www-form-urlencoded”)
如果您使用 Volley Library 通过 POST 请求获取访问令牌, 您可以将参数作为 HashMap 传递,如下所示:
Map<String, String> params = new HashMap<String, String>();
params.put("accept", "application/json");
params.put("Content-Type", "application/x-www-form-urlencoded");
看起来他们使用Spring。并且它要求将
grant_type
作为 application/x-www-form-urlencoded
传递。以及标头中的凭据:
{
'Authorization': `Basic ${base64Encode(clientId:clientSecret)}`,
}
常量主体 = { grant_type: "client_credentials", client_id:"您的client_id", client_secret:"您的客户端秘密", }; 使用这样的标题 标题:{ "内容类型": "application/x-www-form-urlencoded", 接受:“应用程序/json”, }, 由于内容类型是表单 urlencoded,因此必须按如下方式对凭据进行编码。 const bodyDataEncoded = qs.stringify(body); 将此 bodyDataEncoded 作为正文发送,并使用以下 url 生成访问令牌: https://outpost.mappls.com/api/security/oauth/token