0

我正在使用下面的代码,使用 Ebay 的 FindingAPI 来获取 Ebay 匹配关键字的所有项目链接。在这种情况下,“gruen watch”是关键字。此代码不显示超过 100 个项目链接。如何修改它以显示所有项目链接?

**我已经替换了我原来的appid

程序.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 在这里

这是我所做的解决方案:

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();



    }



}



}
4

1 回答 1

1

默认情况下,响应返回的第一页数据最多为 100 项。您可以使用 更改此值paginationInput

findItemsByKeywords 的官方 eBay 文档中,有一个标题为Paginating the Results的部分,它准确地告诉您您需要知道的内容:

使用paginationInput及其子元素来控制在结果集中返回与搜索条件匹配的项目集。用于paginationInput将返回的项目划分为数据的子集或“页面”:

paginationInput.entriesPerPage指定任何给定请求返回的最大项目数

paginationInput.pageNumber指定在当前调用中要返回的数据“页”

默认情况下,响应返回的第一页数据最多为 100 项。以下示例显示如何返回第二页结果,每页最多包含 50 个项目:

...&paginationInput.pageNumber=2&paginationInput.entriesPerPage=50...

在此示例中,假设至少有 100 个匹配项,则响应将包含匹配项 51 到 100。

于 2012-05-07T19:19:23.127 回答