我使用以下代码使用Ebay的FindingAPI来获取Ebay匹配关键字的所有项目链接。在这种情况下,“gruen watch”是关键字。 此代码不会显示超过100个项目的链接。如何修改它以显示所有项链接?
**我已经取代原来的appid
Program.cs的
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TextWriter tw = new StreamWriter("link.txt");
using (FindingServicePortTypeClient client = new FindingServicePortTypeClient())
{
MessageHeader header = MessageHeader.CreateHeader("My-CustomHeader", "http://www.mycustomheader.com", "Custom Header");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(header);
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "MY-APP-ID");
httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");
httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
request.keywords = "gruen watch";
PaginationInput pagination = new PaginationInput();
pagination.entriesPerPageSpecified = true;
pagination.entriesPerPage = 250;
pagination.pageNumberSpecified = true;
pagination.pageNumber = 10;
request.paginationInput = pagination;
FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);
foreach (var item in response.searchResult.item)
{
//Console.WriteLine(item.title);
tw.WriteLine(item.viewItemURL.ToString());
Console.WriteLine(item.viewItemURL.ToString());
}
}
}
tw.Close();
Console.ReadKey();
}
}
app.config是here
这是我所做的解决方案:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TextWriter tw = new StreamWriter("1001.txt");
using (FindingServicePortTypeClient client = new FindingServicePortTypeClient())
{
MessageHeader header = MessageHeader.CreateHeader("My-CustomHeader", "http://www.mycustomheader.com", "Custom Header");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(header);
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "MYAPPID");
httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");
httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
request.keywords = "gruen watch";
FindItemsByKeywordsResponse check = client.findItemsByKeywords(request);
int totalEntries = check.paginationOutput.totalEntries;
int cnt = 0;
int totalPages = (int)Math.Ceiling((double)totalEntries/100.00);
bool flag = true;
for (int curPage = 1; curPage <= totalPages; curPage++)
{
PaginationInput pagination = new PaginationInput();
pagination.entriesPerPageSpecified = true;
pagination.entriesPerPage = 100;
pagination.pageNumberSpecified = true;
pagination.pageNumber = curPage;
request.paginationInput = pagination;
FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);
foreach (var item in response.searchResult.item)
{
Console.WriteLine(item.viewItemURL.ToString());
tw.WriteLine(item.viewItemURL.ToString());
}
}
}
}
tw.Close();
Console.WriteLine("end");
Console.ReadKey();
}
}
}
答案 0 :(得分:1)
默认情况下,响应返回第一页数据,最多返回100个项目。您可以使用paginationInput
更改此值。
在official eBay documentation for findItemsByKeywords上,有一个名为将结果分页的部分,它可以告诉您确切需要知道的内容:
使用
paginationInput
及其子元素来控制在结果集中返回与搜索条件匹配的项目集。使用paginationInput
将返回的项目划分为数据的子集或“页面”:
paginationInput.entriesPerPage
指定最大商品数 返回任何给定的请求
paginationInput.pageNumber
指定 在当前通话中返回哪个“页面”数据默认情况下, 响应返回第一页数据,最多返回100个项目。 以下示例显示如何返回结果的第二页, 每页最多包含50个项目:
...&paginationInput.pageNumber=2&paginationInput.entriesPerPage=50...
在此示例中,响应将包含匹配项51到100,假设至少有100个匹配项。