【问题标题】:How to query a Google My Business API for Insights如何查询 Google My Business API 以获取见解
【发布时间】:2021-01-22 20:06:09
【问题描述】:

我创建了一份报告,其中还希望包含“Google 我的商家”帐户的所有见解。

我已经获得批准并且可以毫无问题地访问 GMB API。唯一的问题是现在我拥有完全访问权限,如何成功查询它以便获得洞察信息?我可以访问一个使用 PHP 或 Python 的团队,所以我想看看我应该给他们什么,以便他们可以成功开始查询。有人可以帮忙吗?

【问题讨论】:

  • 要获得更多有用的答案,显示您尝试过的内容以及未使用 GMB API 的内容可能会很有用。
  • 您好,欢迎来到 Stack Overflow!请添加您已经尝试过的内容,stackoverflow 旨在帮助那些尝试而不仅仅是询问的人。你可能需要从intro tour阅读how to ask

标签: python php google-my-business-api


【解决方案1】:

here下载php客户端库

这是获取位置信息的示例函数

所需参数:

  • locationNames 应作为输入提供
  • startTime 和 endTime 最大差异应为 18 个月 (2020-01-01T15:01:23Z,2021-01-01T15:01:23Z)
   public function getLocationInsights($accountName,$parameters){ 

        // Replace getClientService, with method having accesstoken
        $service = $this->getClientService();
        $insightReqObj = new Google_Service_MyBusiness_ReportLocationInsightsRequest();
        $locationNames = $parameters['locationNames'];

        // Atleast one location mandatory
        if($locationNames && is_array($locationNames) && count($locationNames) <=10){
            $insightReqObj->setLocationNames($locationNames);
        }
        
        $basicReqObj = new Google_Service_MyBusiness_BasicMetricsRequest();
        // datetime range is mandatory
        // TODO :: validate to not allow more than 18 months difference
        $timeRangObj = new Google_Service_MyBusiness_TimeRange();
        $timeRangObj->setStartTime($parameters['startTime']);
        $timeRangObj->setEndTime($parameters['endTime']);

        $metricReqObj = new Google_Service_MyBusiness_MetricRequest();
        $metricReqObj->setMetric('ALL');

        $basicReqObj->setMetricRequests(array($metricReqObj));
        $basicReqObj->setTimeRange($timeRangObj);
        $insightReqObj->setBasicRequest($basicReqObj);
        $allInsights = $service->accounts_locations->reportInsights($accountName,$insightReqObj);
       
        return $allInsights;
    }

【讨论】:

    【解决方案2】:

    我使用 java 来做同样的事情。

    我的是这样的:

    ReportLocationInsightsRequest content = new ReportLocationInsightsRequest();
        content.setFactory(JSON_FACTORY);
        BasicMetricsRequest basicRequest = new BasicMetricsRequest();
    content.setLocationNames("your locationName as a list");
    List<MetricRequest> metricRequests= new ArrayList<MetricRequest>();
        MetricRequest metricR=new MetricRequest();
        String metric="ALL";
        metricR.setMetric(metric);
        metricRequests.add(metricR);
        TimeRange timeRange =new TimeRange();
        timeRange.setStartTime("Desired startTime");
        timeRange.setEndTime("Desired endTime");
        basicRequest.setTimeRange(timeRange );
        content.setBasicRequest(basicRequest );
        try {
            MyBusiness.Accounts.Locations.ReportInsights locationReportInsight= 
                    mybusiness.accounts().locations().reportInsights(accountName, content);
            ReportLocationInsightsResponse response= locationReportInsight.execute();
            System.out.println("response is = "+ response.toPrettyString());
    }catch(Exception e) {
    System.out.println(e);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多