C# eBay 分类法 API Get_Category_Suggestions
C# eBay Taxonomy API Get_Category_Suggestions
我无法使新的 eBay 分类法 API 与使用 C# 的调用 get_category_suggestions 一起正常工作,以替换 eBay 弃用的旧 GetSuggestedCategories 调用。我使用的方法与调用较新的 eBay API 的其他部分时使用的方法完全相同,它可以在分类法 API 中获取默认类别树 ID。以下代码为我获取了 EBAY-US 的树节点 ID,即 124。
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/get_default_category_tree_id?marketplace_id=EBAY-US") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");
然后我使用那个 124 默认类别树 ID 尝试使用具有相同代码的 get_category_suggestions 并完全按照 eBay 的示例 (https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getCategorySuggestions#h2-samples) 但我总是收到来自 eBay 的 404 Not Found 消息。我在这里错过了什么?问题代码如下:
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/get_default_category_tree_id?marketplace_id=EBAY-US") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");request.Headers.Add("Accept-Encoding", "application/gzip");
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");
所以我在调用 getCategorySubtree for the category_tree_id they used the number 0. To be clear the number 0 is not what the documentation for the getCategorySuggestions 状态的文档中看到了这一点。
截至 2021 年 4 月,文档指出您首先需要调用 getDefaultCategoryTree 并将其 return 用作您的 category_tree_id。但是知道 eBay 的运作方式(很糟糕),我尝试使用数字 0 作为 category_tree_id 调用 getCategorySuggestions 并且它起作用了。这是我的最终工作代码,供以后发现此代码的任何人使用。
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/category_tree/0/get_category_suggestions?q=" + title) as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");
我无法使新的 eBay 分类法 API 与使用 C# 的调用 get_category_suggestions 一起正常工作,以替换 eBay 弃用的旧 GetSuggestedCategories 调用。我使用的方法与调用较新的 eBay API 的其他部分时使用的方法完全相同,它可以在分类法 API 中获取默认类别树 ID。以下代码为我获取了 EBAY-US 的树节点 ID,即 124。
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/get_default_category_tree_id?marketplace_id=EBAY-US") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");
然后我使用那个 124 默认类别树 ID 尝试使用具有相同代码的 get_category_suggestions 并完全按照 eBay 的示例 (https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getCategorySuggestions#h2-samples) 但我总是收到来自 eBay 的 404 Not Found 消息。我在这里错过了什么?问题代码如下:
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/get_default_category_tree_id?marketplace_id=EBAY-US") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");request.Headers.Add("Accept-Encoding", "application/gzip");
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");
所以我在调用 getCategorySubtree for the category_tree_id they used the number 0. To be clear the number 0 is not what the documentation for the getCategorySuggestions 状态的文档中看到了这一点。 截至 2021 年 4 月,文档指出您首先需要调用 getDefaultCategoryTree 并将其 return 用作您的 category_tree_id。但是知道 eBay 的运作方式(很糟糕),我尝试使用数字 0 作为 category_tree_id 调用 getCategorySuggestions 并且它起作用了。这是我的最终工作代码,供以后发现此代码的任何人使用。
HttpWebRequest request = WebRequest.Create("https://api.ebay.com/commerce/taxonomy/v1/category_tree/0/get_category_suggestions?q=" + title) as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, System.Web.HttpUtility.HtmlEncode("Bearer " + accessToken));
request.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY-US");
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
log.Debug("starting request.GetRequestStream get_category_suggestions");
string result = null;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
log.Debug("about to load results to json reader");
var reader = new JsonTextReader(new StringReader(result));
log.Debug("successfully loaded results");