API 请求中的身份验证令牌验证失败。 ebay 使用.Net SDK

Validation of the authentication token in API request failed. ebay Using .Net SDK

I want to fetch all products from my store on ebay and this is my code to bring all the data i require. After I register myself on developer program on ebay, i created keys for production. my code is as follow

#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     

After executing this code i am getting this API exception "Validation of the authentication token in API request failed."

Stacktrace:- at 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()

I created keys on production section and clicked on "Get OAuth Application Token " to get Token for "ApiContext.ApiCredential.eBayToken"

Anyone using .NetSDK For ebay API ?

首先,我注意到您的代码是您使用的 API 版本 - 459。

这已经完全过时了,eBay 支持的最低版本是 941

请更新版本试试。以下工作代码版本可能对您有所帮助

https://ebaydts.com/eBayKBDetails?KBid=1686