ebay 新版本对接

本文详细介绍了如何对接eBay新版本API,包括授权步骤、获取access token和refresh token的过程,以及如何使用refresh token更新access token。同时,文章提及了eBay接口的请求次数限制问题,每天共有5000次请求配额,于北京时间下午四点重置,并提供了检查剩余请求次数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一 授权步骤

 第一步:
    Getting user consent | eBay Developers Program
先拼接url然后让客户点击跳转给你授权,客户同意授权之后ebay调用你配置好的回调地址给你返回access token,最好加上state。
重点参数解释

Query ParameterDescription

client_id

The client_id value for the environment you're targeting.

Occurrence: Required

locale

The locale parameter to localize the OAuth consent page for the marketplace you're targeting. For example, set locale=de-DE for Germany. See the Locale Support column of the Marketplace ID values table for the supported locales.

Occurrence: Optional

prompt

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 login.

Occurrence: Optional

redirect_uri

The RuName value for the environment you're targeting.

For details, see Getting your redirect_uri value.

Occurrence: Required

response_type

Set to "code" to have eBay generate and return an authorization code.

Occurrence: Required

scope

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

state

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,就是在开发者后台的这里

这个真的很感谢告知我的一位大哥,万分感谢,祝你事业顺利,生活幸福美满

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值