Ana SayfaBelgelerKod ÖrnekleriAPI BaşvurusuDuyurularModellerSürüm NotlarıSSSGitHubVideolar
Geliştirici MerkeziAPI DurumuDestek
Belgeler
Geliştirici MerkeziAPI DurumuDestek

Oluşturulan bir C# SDK'sını kullanarak Satış Ortağı API'sine bağlanma

Oluşturulan bir C# SDK kullanarak SP-API'ye bağlanın.

This tutorial describes how to use a generated C# Software Developer Kit (SDK) to make API 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 Generate a C# SDK with LWA token generation and authentication.

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

You must also install the following dependencies via NuGet in Visual Studio:

  • JsonSubTypes 1.2.0 veya tümü
  • Newtonsoft.json 12.0.3 veya tümü
  • RestSharp 106.12.0
  • RateLimiter 2.2.0 veya daha yenisi (bu da yüklenecek ComposableAsync.Core)

3. Adım: LWA kimlik bilgilerinizi yapılandırın

Şu parametreleri kullanarak bir LWAAuthorizationCredentials örneği oluşturun:

AdAçıklamaZorunlu mu?
ClientIdYour LWA client identifier. For more information, refer to Viewing your application information and credentials.Evet
ClientSecretYour LWA client secret. For more information, refer to Viewing your application information and credentials.Evet
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 Scopes.
Scopes

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

No. Include Scopes if the operation that you call in the following step is a grantless operation. If you include Scopes, do not include the RefreshToken.
EndpointLWA kimlik doğrulama sunucusu URI'si.Evet

Satış ortağı yetkilendirmesi gerektiren bir işlem çağrısı örneği:

using Amazon.SellingPartnerAPIAA; LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials { ClientId = "myClientId", ClientSecret = "myClientSecret", RefreshToken = "Aztr|...", Endpoint = new Uri(""https://api.amazon.com/auth/o2/token"") };

İzinsiz işlem çağrısı örneği

using Amazon.SellingPartnerAPIAA; LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials { ClientId = "myClientId", ClientSecret = "myClientSecret", Scopes = new List<string>() { ScopeConstants.ScopeNotificationsAPI, ScopeConstants.ScopeMigrationAPI } Endpoint = new Uri(""https://api.amazon.com/auth/o2/token"") };

3. Adım: Satıcılar API'sinin bir örneğini oluşturup bir işleme çağrı yapın

After you configure your LWAAuthorizationCredentials, you can create an instance of SellersApi and call an operation.

Örnek:

SellersApi sellersApi = new SellersApi.Builder() .SetLWAAuthorizationCredentials(lwaAuthorizationCredentials) .Build();

C# SDK'de Sorun Giderme

IRestRequest hataları: "RestSharp Version=105.0.0.0. Culture=neutral. PublicKevToken=598062e77f915f75, referans verilmeyen bir assembly'de tanımlandı. {{2}} şeklindeki assembly için referans eklemeniz gerekiyor"

Burayı seçerek cevabı genişletebilirsiniz. {{0}} paketini 106.12.0.0 sürümüne güncelleyin. 106.12 sürümünün başarıyla güncellendiğinden emin olmak için referansa göz atın. 105.0.0.0 sürümü gösterilmeye devam ediyorsa eski sürümü referanstan kaldırın ve 106.12.0.0 paketini, oluşturulan istemci kütüphanesinin bulunduğu paketler klasöründen manuel olarak ekleyin.

"{{0}} türü veya ad alanı adı bulunamadı (kullanma yönergeniz veya assembly referansınız mı eksik?)"

Yanıtı genişletmek için seçin.

In some scenarios, even though you have the required version in the NuGet packages for Newtonsoft, it requires manual addition from the package folder in the file system. To resolve this, use the following steps:

  1. In Visual Studio, right-click your generated SDK package and choose Add, then References.

  2. On the references window in the .Net Assembly, choose browse.

  3. Navigate to the generated client library folder in local > packages and add the specific package for Newtonsoft.

"Mesaj: SellingPartnerAPI.servicesApi.Client.ApiClient:rateLimiter (3) alan türü şu nedenle yüklenemedi: ComposableAsync.Core, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null şeklindeki dosya veya assembly ya da bağımlılarından biri yüklenemedi."

Yanıtı genişletmek için seçin.

Kodunuzu oluşturup çalıştırdıktan sonra bu hatayı alıyorsanız ComposableAsync.Core bağımlılık paketi indirilmiş ancak referans olarak eklenmemiştir. Dll'yi manuel bir şekilde referans olarak eklediğinizden emin olun.

Modellerle ilgili eşleme sorunları

Yanıtı genişletmek için seçin.

The ItemAsin model was generated with the JsonObject type, but the required string ItemAttributes requires the JsonObjectAttribute. You can use this command, which uses the Catalog Items API, to import the required mapping for the models :

`java -jar swagger-codegen-cli.jar generate -i catalogItems_2022-04-01.json -l csharp -t sellingpartner-api-aa-csharp\src\Amazon.SellingPartnerAPIAA\resources\swagger-codegen\templates —import-mappings ItemAttributes=Newtonsoft.Json.JsonObjectAttribute —import-mappings ItemAsin=System.string -o catalogItems2022-04-01_import`

HttpRequestHeaders.ToJson(): geçersiz kılacak uygun bir yöntem bulunamadı."

Yanıtı genişletmek için seçin.

override anahtar kelimesini virtual ile değiştirin. Yöntemler, geçersiz kılınabilmeleri için virtual olmalıdır.

public virtual string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); }

"BaseValidate adı geçerli bağlamda mevcut değil"

Yanıtı genişletmek için seçin.

Sınıfta belirtilen yöntemlerin yorumunu kaldırın:

// IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) // { // foreach (var x in BaseValidate(validationContext)) // yield return x; // yield break; // }

Bu sayfa size yardımcı oldu mu?