主页文档代码示例API 参考公告模型发行说明常见问题GitHub视频
开发者中心API 状态支持
文档
开发者中心API 状态支持

使用生成的 Java SDK 连接到销售伙伴 API

如何使用生成的 Java SDK 连接到 SP-API。

Before your application can connect to the Selling Partner API, you must register it, and it must be authorized by a selling partner. Refer to Registering your application and Authorizing Selling Partner API applications.

These instructions show you how to use a generated Java SDK to make calls. The SDK exposes classes for configuring your Login with Amazon (LWA) credentials and uses them to generate LWA tokens and sign requests for you. For more information, refer to Generating a Java SDK with LWA token exchange.

步骤 3. 配置您的 AWS 凭证

使用以下参数,创建 LWAAuthorizationCredentials 的实例:

名称描述必填项
clientIdYour LWA client identifier. For more information, refer to Viewing your developer information.有帮助
clientSecretYour LWA client secret. For more information, refer to Viewing your developer information.有帮助
refreshTokenThe LWA refresh token. Get this value when the selling partner authorizes your application. For more information, refer to Authorizing Selling Partner API applications.

No. Include refreshToken if the operation that you call in the following step requires selling partner authorization. All operations that are not grantless operations require selling partner authorization. If you include refreshToken, do not include withScopes.

withScopes

The scope of the LWA authorization grant. Takes the value ScopeNotificationsAPI for the Notifications API.

No. Include withScopes if the operation that you call in the following step is a grantless operation. If you include withScopes, do not include refreshToken.
endpointLWA 身份验证服务器 URI。有帮助

调用需要销售伙伴授权的操作的示例:

import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials; LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder() .clientId("myClientId") .clientSecret("myClientSecret") .refreshToken("Aztr|...") .endpoint("https://api.amazon.com/auth/o2/token") .build();

调用免授权操作的示例:

import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials; import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_NOTIFICATIONS_API; import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_MIGRATION_API; LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder() .clientId("myClientId") .clientSecret("myClientSecret") .withScopes(SCOPE_NOTIFICATIONS_API, SCOPE_MIGRATION_API) .endpoint("https://api.amazon.com/auth/o2/token") .build();

步骤 3. 创建卖家 API 实例并调用操作

和你的 LWAAuthorizationCredentials 已配置的实例,您可以创建的实例 SellersApi 并调用一个操作。

示例:

SellersApi sellersApi = new SellersApi.Builder() .lwaAuthorizationCredentials(lwaAuthorizationCredentials) .endpoint("https://sellingpartnerapi-na.amazon.com") .build();

此页面对您有帮助吗?