如何在Java中发送请求到业务配置文件性能API?

osh3o9ms  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(145)

有人知道我如何使用Java向这个API发送请求吗?链接是Business Profile Performance API,但没有代码示例。我尝试的代码不正确:假设businessProfilePerformance是BusinessProfilePerformance类型的变量,以通过其构建器初始化全局参数,并且还负责授权。

try {

BusinessProfilePerformance.Locations.GetDailyMetricsTimeSeries metricReport = businessProfilePerformance.locations()
                                .getDailyMetricsTimeSeries(locationName);
                        GetDailyMetricsTimeSeriesResponse response = metricReport.execute();
                        if (!response.isEmpty()) {
                            System.out.println("Response== " + response);
                        }

                    } catch (Exception e) {
                        System.out.println(e);
                    }

错误是
服务器响应异常:400错误请求

{
  "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"
}

谢啦,谢啦

eoxn13cs

eoxn13cs1#

我找到答案了。我把它放在这里以防有人会想到:假设变量business_profile_performance是通过其构建器的初始化器全局参数,并且还负责认证。

try {

            BusinessProfilePerformance.Locations.GetDailyMetricsTimeSeries metricReport =
                    business_profile_perfomance.locations().
                    getDailyMetricsTimeSeries("My locationID" ).
                    setDailyMetric(dailyMetric).
                    setDailyRangeStartDateYear(Integer.valueOf("the desired start Year")).
                    setDailyRangeStartDateMonth(Integer.valueOf(" the desired start Month" )).
                    setDailyRangeStartDateDay(Integer.valueOf(" the desired start Day ")).

                    setDailyRangeEndDateYear(Integer.valueOf("the desired End Year" )).
                    setDailyRangeEndDateMonth(Integer.valueOf(" the desired End Month")).
                    setDailyRangeEndDateDay(Integer.valueOf("the desired End Day"));

            GetDailyMetricsTimeSeriesResponse response = metricReport.execute();
            if (!response.isEmpty()) {
                System.out.println(dailyMetric + " Response == " + response);
            }

        } catch (Exception e) {
            System.out.println(e);
        }

变量 dailyMetric 可以是下图所示的指标之一:

相关问题