mapmyindia 对如何获取 OAuth 感到困惑

问题描述 投票:0回答:3

我已阅读 此网站上的 OAuth 文档。

但我仍然对请求 url 的格式感到困惑。

任何帮助都会很棒。

mapmyindia-api
3个回答
2
投票

您可以使用以下请求网址来生成访问令牌,

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");

1
投票

看起来他们使用Spring。并且它要求将

grant_type
作为
application/x-www-form-urlencoded
传递。以及标头中的凭据:

{
  'Authorization': `Basic ${base64Encode(clientId:clientSecret)}`,
}

0
投票

常量主体 = { 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

© www.soinside.com 2019 - 2024. All rights reserved.