一 授权步骤
第一步:
Getting user consent | eBay Developers Program
先拼接url然后让客户点击跳转给你授权,客户同意授权之后ebay调用你配置好的回调地址给你返回access token,最好加上state。
重点参数解释
Query Parameter | Description |
---|---|
| The client_id value for the environment you're targeting. Occurrence: Required |
| The locale parameter to localize the OAuth consent page for the marketplace you're targeting. For example, set Occurrence: Optional |
| If needed, you can force a user to log in when you redirect them to the Grant Application Access page, even if they already have an existing user session. To do so, set the prompt query parameter to Occurrence: Optional |
redirect_uri | The RuName value for the environment you're targeting. For details, see Getting your redirect_uri value. Occurrence: Required |
| Set to " Occurrence: Required |
| A list of OAuth scopes that provide access to the resources used by your application. For details, see Using OAuth to access eBay APIs Occurrence: Required |
| An opaque value used by the client to maintain state between the request and callback. The authorization server returns the same value supplied in the request when it redirects the user-agent back to the client's accept URL. While the state value is optional, we recommend you supply this value and use it to prevent cross-site request forgery, as described in Section 10.12 of the OAuth spec. Occurrence: Optional |
GET https://auth.sandbox.ebay.com/oauth2/authorize? client_id=<app-client-id-value>& locale=<locale-value>& // optional prompt=login // optional redirect_uri=<app-RuName-value>& response_type=code& scope=<scopeList>& // a URL-encoded string of space-separated scopes state=<custom-state-value>& // optional
返回
https://www.example.com/acceptURL.html? state=<client_supplied_state_value>& code=v%5E1.1% ... NjA%3D& expires_in=299 客户点击同意之后ebay回调你配置在后台的回调地址,我们需要code这个参数,这样你就得到了客户的授权码,这个码不是accesstoken,accesstoken还在下一步,这个码不需要存哈,才299秒有效期的东西,这个码使用在下一步的。
第二步 :组装url请求accesstoken 等
Exchanging the authorization code for a User access token | eBay Developers Program
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: grant_type=authorization_code code=<authorization-code-value> redirect_uri=<RuName-value> 返回
{ "access_token": "v^1.1#i^1#p^3#r^1...XzMjRV4xMjg0", "expires_in": 7200, "refresh_token": "v^1.1#i^1#p^3#r^1...zYjRV4xMjg0", "refresh_token_expires_in": 47304000, "token_type": "User Access Token" }
refresh_token 存起来 accesstoken 就是请求需要的token,有效期两个小时,refresh_token就是用来accesstoken失效之后再请求的东西
第三步:用refresh_token更新accesstoken
Using a refresh token to update a User access token | eBay Developers Program
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: grant_type=refresh_token refresh_token=<your-refresh-token-value> scope=<scopeList> // a URL-encoded string of space-separated scopes
返回
{ "access_token": "v^1.1#i ... AjRV4yNjA=", "expires_in": 7200, "token_type":"User Access Token" }
ebay 接口请求次数限制问题 Getting access tokens through the Developer Portal | eBay Developers Program
我这儿主要用的是拉单和站内信相关接口,他们居然共享次数,一共每天5000次,北京时间下午四点清空次数,查看接口剩余次数请求这个链接
https://api.ebay.com/developer/analytics/v1_beta/rate_limit/?api_context=tradingapi
返回格式如下
remaining是剩余的请求次数
我直接用的postman请求的,注意,这个token是你APP的token,就是在开发者后台的这里
这个真的很感谢告知我的一位大哥,万分感谢,祝你事业顺利,生活幸福美满