使用生成的 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
的实例:
名称 | 描述 | 必填项 |
---|---|---|
clientId | Your LWA client identifier. For more information, refer to Viewing your developer information. | 有帮助 |
clientSecret | Your LWA client secret. For more information, refer to Viewing your developer information. | 有帮助 |
refreshToken | The 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 |
withScopes | The scope of the LWA authorization grant. Takes the value | 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. |
endpoint | LWA 身份验证服务器 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();
Updated 6 months ago