如何发送请求到Java中的Business Profile Performance API以获取搜索关键字?

pdkcd3nj  于 2023-01-29  发布在  Java
关注(0)|答案(1)|浏览(102)

我使用Business Profile Performance API来获取用于在搜索或Map中查找企业的搜索关键字。假设business_profile_performance是BusinessProfilePerformance API类型的初始化变量,它也负责凭据:

try{ 
                   BusinessProfilePerformance.Locations.Searchkeywords.Impressions.Monthly.List impressionsList= business_profile_performance.
locations().searchkeywords().impressions().monthly().list("locations/"+locationName);               
                ListSearchKeywordImpressionsMonthlyResponse response = impressionsList.execute();
                                        List<SearchKeywordCount>  impressions = response.getSearchKeywordsCounts();
                                         System.out.println("Size is "+ impressions.size());
                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }

它给了我错误:

{
  "code" : 400,
  "details" : [ {
    "@type" : "type.googleapis.com/google.rpc.BadRequest"
  } ],
  "errors" : [ {
    "domain" : "global",
    "message" : "Request contains an invalid argument.",
    "reason" : "badRequest"
  } ],
  "message" : "Request contains an invalid argument.",
  "status" : "INVALID_ARGUMENT"
}

任何帮助都将不胜感激。谢谢。

taor4pac

taor4pac1#

好的我找到答案了,我没有发送月份范围:

LocalDate localDate = LocalDate.now();
        
        localDate= localDate.minusMonths(1);
        int endYear= localDate.getYear() ;
        int endMonth= localDate.getMonthValue() ;
        
        localDate= localDate.minusMonths(1);
        int startYear= localDate.getYear() ;
        int startMonth= localDate.getMonthValue() ;
     
        try {

            BusinessProfilePerformance.Locations.Searchkeywords.Impressions.Monthly.List impressions
            = business_profile_performance.locations().searchkeywords().impressions().monthly().list("locations/"+locationName)
            
            .setMonthlyRangeEndMonthYear(endYear)
            .setMonthlyRangeEndMonthMonth(endMonth)
             
            .setMonthlyRangeStartMonthYear(startYear)
            .setMonthlyRangeStartMonthMonth(startMonth);

            ListSearchKeywordImpressionsMonthlyResponse response = impressions.execute();    
            System.out.println(response.toString());

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

相关问题