Ebay API:“开发者帐户”与“开发者帐户”之间的连接和“Ebay 帐户”

发布于 2025-01-16 14:59:05 字数 397 浏览 1 评论 0原文

我刚刚开始熟悉 eBay RESTful API,请原谅我这个基本问题,但我还没有找到答案。

我多年前就有一个 eBay 帐户。我最近注册了一个开发者帐户(相同的电子邮件地址),并获得了沙盒和生产的令牌。我已成功使用公共 API(如列表项、搜索项等)通过查询 eBay 中的某些项目来验证令牌。

我如何从此处继续访问特定于我的 eBay 帐户的数据,例如购买和销售列表?我想,我需要以某种方式将我的应用程序连接到我的实时 eBay 帐户,并授予我的应用程序读取数据的权限,但我在 eBay 帐户设置和 API 调用中都找不到任何匹配的设置。

请指导我完成下一步:如何为我的应用程序提供所需的权限,以及如何构建一个简单的只读查询来查询,例如,我已购买的商品。

我认为这个问题不依赖于任何编程语言,随意使用你喜欢的任何编程语言。

I am just beginning to familiarize myself with the eBay RESTful API, forgive me this basic question, but I found no answer yet.

I have an eBay account since many years ago. I registered a developer account (same email address) recently, and I got the Tokens for Sandbox and Production. I have successfully used public APIs like list items, search items, and such, to verify the tokens, by querying some items in eBay.

How do I proceed from here to access data specific to my eBay account, like, for instance, the list of purchases and sales? Somehow I need to connect my app to my live eBay account, I guess, and give my app permissions to read data, but I could not find any matching setting in my eBay account settings nor in the API calls.

Please guide me through the next step: how do I give my app the required permissions, and how do I build a simple read-only query to query, for instance, the items I have purchased.

I think this question does not depend on any programming language, feel free to use any programming language you like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2025-01-23 14:59:05

好吧,如果我们只讨论授权令牌并调用类似订单的卖家 api(我相信在 eBay 中这称为履行)。

我们需要从创建用户令牌开始。

您可以在此处创建一个:
输入图像描述这里

然后您需要添加 eBay 重定向 URL:

在此处输入图像描述

我对 Auth'n'Auth 不太了解,所以我只讨论 OAuth

添加新的重定向 URL 后,您应该添加授权成功和失败的 url 地址。
授权后您将被重定向到那里。

现在我们可以测试令牌的生成是否有效。

对于这个例子,我确实设置了我的重定向网址,如下所示:

在此处输入图像描述

我们需要单击“测试登录”(之前将单选按钮设置为 OAuth)
您应该被重定向到网站:

在此处输入图片描述

您需要使用有权访问 sandbox.ebay.com 或 ebay.com 的帐户登录(取决于您是在沙箱还是生产环境中)

登录后我不知道不记得是否将会出现另一个窗口,其中包含要确认的应用程序范围(我之前已经做过)。
但如果是这种情况,只需单击确认按钮即可。

现在您应该被重定向到 https://localhost.com 这是我们设置的,因为我们的成功重定向 URL

应该如下所示那个

https://localhost.com/?code=v%5E1.1%0VeMTI%3D%3D&expires_in=299

那个代码顺便说一句,参数要长得多。 您可以看到它是 url 编码的,因此您需要在使用之前对其进行解码

现在您几乎已经熟悉了 :D

您有 300 秒的时间来调用 POST 请求以使用该代码参数进行授权。

POST https://api.sandbox.ebay.com/identity/v1/oauth2/token

需要标头

还记得第一个屏幕截图吗?

您需要去那里获取您的应用程序 ID、证书 ID,然后将其与“:”连接,然后将其编码为 Base64 并在该值之前添加“Basic”关键字。

在伪代码中,它应该如下所示:

Authorization:Basic Base64.encode(AppID + ":" + CertID)

Body required

Body 格式需要为“x-www” -form-urlencoded”(基本上是键:值格式)

这里您需要

grant_type:authorization_code

code:{code}

redirect_uri:{redirect_name}

{code} - 是来自成功授权 url 的值
{redirect_name} - 您可以在下面标有红色圆圈的屏幕上找到它

在此处输入图像描述

如果您所做的一切正确,您应该从 eBay 获得响应

{
    "access_token": "v^1.1#i^1#r^0VbbxW1wjv4HZGAAA",
    "expires_in": 7200,
    "refresh_token": "v^1.1#i^1#f^0#r^FDQ=",
    "refresh_token_expires_in": 47304000,
    "token_type": "User Access Token"
}

您应该保存该数据,access_token 用于访问数据,refresh_token 用于刷新access_token。

使用 authToken 的示例请求

GET https://api.sandbox.ebay.com/sell/fulfillment/v1/order?filter=creationdate:[2022-03-31T08:25:43.511Z..]

You need Authroization header:
Authorization:Bearer v^1.1#i^1#r^0VbbxW1wjv4HZGAAA

我猜就是这样。要将其实现到您的应用程序中,您需要能够生成单击“测试登录”后重定向到的第一个网址,基本上就是这样。

一样刷新令牌

顺便说一句,您像POST https://api.sandbox.ebay.com/ Identity/v1/oauth2/token

正文 x-www-form-urlencoded

grant_type:refresh_token

刷新令牌:v^1.1#i^1#f^0#r^FDQ=

标头
Authorization:Basic Base64.encode(AppID + ":" + CertID)

我希望这会对某人有所帮助。 :)

Ok so if we are talking only about Authorization token and calling seller api like orders (in ebay it's called fullfilments i believe).

We need to start with creating User Token.

You can create one here:
enter image description here

Then you need to add ebay redirect URL:

enter image description here

I don't know much about Auth'n'Auth so I will talk only about OAuth

After adding new redirect URL you should add url address for authorization success and failure.
You will be redirected there after authorization.

Now we can test if generation of token works.

For this example i did set my redirect url like that:

enter image description here

We need to click "Test Sign-in" (set radio button to OAuth before)
You should be redirected to website:

enter image description here

You need to sign in with account which have access to sandbox.ebay.com or ebay.com (depends if you are on sandbox or production environment)

After logging in I don't remember if there will be another window with confirmation of App scopes to confirm (I already done it before).
But if that is the case just click confirm button.

Now you should be redirected to https://localhost.com which we did set up as our success redirect url

Url should look like that

https://localhost.com/?code=v%5E1.1%0VeMTI%3D%3D&expires_in=299

That code parameter is much longer btw. And you can see that it's url encoded so you need to decode it before using

And now you are almost at home :D

You have 300 seconds to call a POST request to authorize with that code parameter.

POST https://api.sandbox.ebay.com/identity/v1/oauth2/token

Header required

Remember first screen shot?

You need to go there and get your App ID, Cert ID then concatenate it with ":" then encode it to Base64 and add before that value "Basic " keyword.

In pseudo code it should looks like that:

Authorization:Basic Base64.encode(AppID + ":" + CertID)

Body required

format of Body needs to be "x-www-form-urlencoded" (key:value format basically)

here you need

grant_type:authorization_code

code:{code}

redirect_uri:{redirect_name}

{code} - is value from success authorization url
{redirect_name} - you can find it on screen below marked with red circle

enter image description here

If you did everything right you should get response from ebay

{
    "access_token": "v^1.1#i^1#r^0VbbxW1wjv4HZGAAA",
    "expires_in": 7200,
    "refresh_token": "v^1.1#i^1#f^0#r^FDQ=",
    "refresh_token_expires_in": 47304000,
    "token_type": "User Access Token"
}

You should save that data, access_token is used for accessing data, refresh_token is used to refresh access_token.

Example request with authToken

GET https://api.sandbox.ebay.com/sell/fulfillment/v1/order?filter=creationdate:[2022-03-31T08:25:43.511Z..]

You need Authroization header:
Authorization:Bearer v^1.1#i^1#r^0VbbxW1wjv4HZGAAA

That's it I guess. To implement that into your app you need to be able to generate the first url which you are redirected to after clicking "Test Sign-in" and that's basically it.

Btw you refresh token like that

POST https://api.sandbox.ebay.com/identity/v1/oauth2/token

Body x-www-form-urlencoded

grant_type:refresh_token

refresh_token:v^1.1#i^1#f^0#r^FDQ=

Header
Authorization:Basic Base64.encode(AppID + ":" + CertID)

I hope that will help someone. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文