通过eBay token 认证苦苦挣扎了几天。
我发现很难理解如何获取新 token ,在注册开发人员程序帐户后,我请求了密钥集并获得了它们,然后我授予对Auth'n'Auth token 的访问权限,该 token 将持续18个月,是的,该 token 仅适用于Trading,Shopping和Finding API。
但是,当您需要执行Buy,Sell和Commerce API时,您必须获取oauth token 。您可以使用用户 token 工具在oauth上进行所谓的“单一用户应用”风格和登录,并在2小时后获得oauth。
稍后, token 将过期,您可能会失去对上述api的访问权限。我尝试从“交易”>“获取 session ID”,“交易”>“获取 token ”中获取 token ,但是在将 session ID提供给“获取 token ”后,它说:“最终用户尚未完成Auth&Auth登录流程。”尽管有有效的18个月 token ,但它会不断返回此错误。
是否有任何人可能读过或写过的示例文章?
最佳答案
这详细说明了“New Sell” API(而非auth'n'auth或旧版Trading API)的OAuth流程。尽管生产过程相同,但也适用于沙箱。
您的困惑并非没有根据。我自己在使用此API流程以及大部分official dev forums流程时所经历的事情非常紧张。下面详细说明了生成oauth 不相关的过程,该过程与您是否要连接到单个,专用帐户或多个用户帐户有关。
有official guide,它说明了整个过程,所以我犹豫在这里重新创建整个指南。不过,我可以提供摘要(建议您在尝试通过您的应用前,先使用Postman遵循以下内容):
https://api.ebay.com/oauth/api_scope/sell.inventory
范围。找出所需的端点,并转到每个端点的API文档,然后找到“作用域”部分。`https://signin.sandbox.ebay.com/authorize?
client_id=<your-client-id-value>&
redirect_uri=<your-RuName-value>&
response_type=code&
scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.account%20
https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.inventory`
还建议您添加state
查询字符串,为便于使用,我已省略了该查询字符串,但是您应该研究what they are以及为什么建议将它们用于OAuth。重要提示:即使您的应用程序仅具有一个用户,也需要最终用户签名。例如,您有一个客户的电子商务网站,并且想要将他们的产品发送到他们的单一eBay帐户。您仍然需要每18个月至少执行一次此过程(找出为什么很快)。
code
查询字符串。如果您正在为多个用户开发一个应用程序,并计划让他们实际在此页面上登录,则需要配置您的应用程序以获取确认响应(即上述URL),并从中提取代码。这段代码是短暂的。如果要通过浏览器手动检索它,则需要快速完成下一步。HTTP method: POST
URL (Sandbox): https://api.sandbox.ebay.com/identity/v1/oauth2/token
HTTP headers:
Content-Type = application/x-www-form-urlencoded
Authorization = Basic <B64-encoded-oauth-credentials> (A base64-encoded value made from your client ID and client secret, separated by colon. For example, in PHP you could generate it with: `base64_encode ("fakeclientid123:fakeclientsecret123")`)
Request body (wrapped for readability):
grant_type=authorization_code& (literally the string "authorization_code")
code=<authorization-code-value>& (code retreived in previous step)
redirect_uri=<RuName-value> (same RuName as earlier)
如果成功,此请求将返回如下内容:{
"access_token": "v^1.1#i^1#p^3#r^1...XzMjRV4xMjg0",
"token_type": "User token",
"expires_in": 7200,
"refresh_token": "v^1.1#i^1#p^3#r^1...zYjRV4xMjg0",
"refresh_token_expires_in": 47304000
}
我们正在使用oauth token ,该 token 将持续 2小时。第二个 token 是刷新 token ,将持续约18个月。确保此 token 安全,不要共享它,也不要在您的应用中对其进行硬编码。从那时起,您的应用应使用此 token 执行刷新调用,以在需要时获取新的oauth。 18个月结束后,或者如果用户再次执行“允许访问”过程,则需要执行上述所有操作来生成新的刷新 token 。假设此时API尚未更改。值得注意的是,18个月的寿命不是OAuth刷新的常规过程,通常,每次使用旧的 token 时,OAuth都会返回一个新的刷新 token 。
HTTP method: POST
URL (Sandbox): https://api.sandbox.ebay.com/identity/v1/oauth2/token
HTTP headers:
Content-Type = application/x-www-form-urlencoded
Authorization = Basic <B64-encoded-oauth-credentials>
Request body (wrapped for readability):
grant_type=refresh_token&
refresh_token=<your-refresh-token-value>&
scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.account%20
https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.inventory
我希望这有帮助!
关于oauth - eBay oauth token 和刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603838/