我想在ebay上从我的商店获取所有产品,这是我的代码 带来我需要的所有数据。在我注册开发人员之后 在ebay上的程序,我创建了生产密钥。我的代码如下
#region Feilds
ApiContext ApiContext = new ApiContext();
CallRetry OCallRetry = new CallRetry();
ApiCall ApiCall = new ApiCall();
GetItemCall GetCall = new GetItemCall();
#endregion
#region Utilities
public void GetCredentials()
{
ApiContext.ApiCredential.ApiAccount.Developer = "xxxxxxxx"; //use your dev ID
ApiContext.ApiCredential.ApiAccount.Application = "xxxxxx"; //use your app ID
ApiContext.ApiCredential.ApiAccount.Certificate = "xxxxxxxxxxxx"; //use your cert ID
ApiContext.ApiCredential.eBayToken = ConfigurationManager.AppSettings["Token"]; //set the AuthToken
}
public void InitializeAPI()
{
ApiContext.SoapApiServerUrl = "https://api.ebay.com/wsapi";
ApiContext.Site = eBay.Service.Core.Soap.SiteCodeType.India;
ApiContext.Version = "459";
}
public void SetupAPILog()
{
//very important, let's setup the logging
ApiLogManager ApiLog = new ApiLogManager();
ApiLog.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("GetSellerList459NETSDK.log", true, true, true));
ApiLog.EnableLogging = true;
ApiContext.ApiLogManager = ApiLog;
}
public void ConsumeAPI()
{
OCallRetry.DelayTime = 1;
OCallRetry.MaximumRetries = 3;
StringCollection oErrorCodes = new StringCollection();
oErrorCodes.Add("10007");
oErrorCodes.Add("2");
oErrorCodes.Add("251");
OCallRetry.TriggerErrorCodes = oErrorCodes;
TypeCollection oExceptions = new TypeCollection();
oExceptions.Add(typeof(System.Net.ProtocolViolationException));
oExceptions.Add(typeof(SdkException));
OCallRetry.TriggerExceptions = oExceptions;
ApiContext.CallRetry = OCallRetry;
ApiContext.Timeout = 120000;
GetSellerListCall ApiSellerList = new GetSellerListCall(ApiContext);
ApiSellerList.Version = ApiContext.Version;
ApiSellerList.Site = ApiContext.Site;
ApiSellerList.GranularityLevel = eBay.Service.Core.Soap.GranularityLevelCodeType.Fine;
// enable the compression feature
ApiSellerList.EnableCompression = true;
ApiSellerList.DetailLevelList.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ReturnAll);
PaginationType oPagination = new PaginationType();
oPagination.EntriesPerPage = 200;
oPagination.EntriesPerPageSpecified = true;
oPagination.PageNumber = 1;
oPagination.PageNumberSpecified = true;
ApiSellerList.Pagination = oPagination;
ApiSellerList.EndTimeFilter = new TimeFilter(DateTime.Now, DateTime.Now.AddMonths(3));
ApiSellerList.Sort = 2;
try
{
ItemTypeCollection oItems = ApiSellerList.GetSellerList();
foreach (ItemType oItem in oItems)
{
Console.WriteLine("ItemID is " + oItem.ItemID);
Console.WriteLine("This item is of type " + oItem.ListingType.ToString());
if (0 < oItem.SellingStatus.BidCount)
{
// The HighBidder element is valid only if there is at least 1 bid
Console.WriteLine("High Bidder is " + oItem.SellingStatus.HighBidder.UserID);
}
Console.WriteLine("Current Price is " + oItem.SellingStatus.CurrentPrice.currencyID.ToString() + " " + oItem.SellingStatus.CurrentPrice.Value.ToString());
Console.WriteLine("End Time is " + oItem.ListingDetails.EndTime.ToLongDateString() + " " + oItem.ListingDetails.EndTime.ToLongTimeString());
Console.WriteLine("");
// the data that is accessible through the item object
// for different GranularityLevel and DetailLevel choices
// can be found at the following URL:
// http://developer.ebay.com/DevZone/SOAP/docs/WebHelp/GetSellerListCall-GetSellerList_Best_Practices.html
}
}
catch (ApiException oApiEx)
{
// process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do
Console.WriteLine(oApiEx.Message);
return;
}
catch (SdkException oSdkEx)
{
// process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do
Console.WriteLine(oSdkEx.Message);
return;
}
catch (Exception oEx)
{
// process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do
Console.WriteLine(oEx.Message);
return;
}
}
#endregion
执行此代码后,我收到此API异常&#34;验证 API请求中的身份验证令牌失败。&#34;
Stacktrace: - 在eBay.Service.Core.Sdk.ApiCall.SendRequest()at eBay.Service.Core.Sdk.ApiCall.Execute()at eBay.Service.Call.GetSellerListCall.GetSellerList()at Nop.Services.EbayExport.ExportProducts.ConsumeAPI()
我在生产部分创建了密钥,然后点击了&#34;获取OAuth 应用程序令牌&#34;得到令牌 &#34; ApiContext.ApiCredential.eBayToken&#34;
任何人使用.NetSDK for ebay API?
答案 0 :(得分:0)
首先,我在您的代码中注意到您使用的API版本 - 459。
现在这已经过时了,eBay支持的最低版本是941
请更新版本并尝试。以下工作代码版本可以帮助您