Google Analytics分析API,获取列表帐户-gapi.client.analytics.management未定义

问题描述

我将这行代码添加到了我的工作代码

// Do the magic const  
request = gapi.client.analytics.management.accountSummaries.list();
  request.execute(handleResponse)

并得到此错误,为什么未定义“管理”?我需要更改什么?

Uncaught TypeError: Cannot read property 'management' of undefined
    at queryReports

所有代码

enter code here
<!DOCTYPE html>
<html>
<head>
  <Meta charset="utf-8">
  
  <Meta name="google-signin-client_id" content="client_id">
  <Meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/userinfo.email">
</head>
<body>

<!-- The Sign-in button. This will run `queryReports()` on success. -->
<p class="g-signin2" data-onsuccess="queryReports"></p>


<script>
  // Replace with your view ID.
  var VIEW_ID = 'ga:104831427';

let userEmail ; 
let userId;
let fullName;
let firstName;
let lastName;
let idToken;
let request;


  // Query the API and print the results to the page.
  function queryReports(googleUser) {



 var profile = googleUser.getBasicProfile();

userId = profile.getId();

fullName = profile.getName();

firstName = profile.getGivenname();

lastName = profile.getFamilyName();

userEmail = profile.getEmail();

idToken = googleUser.getAuthResponse().id_token;

// Do the magic const  
request = gapi.client.analytics.management.accountSummaries.list();
  request.execute(handleResponse)



 




    gapi.client.request({
      path: '/v4/reports:batchGet',root: 'https://analyticsreporting.googleapis.com/',method: 'POST',body: {
        reportRequests: [
          {
            viewId: VIEW_ID,dateranges: [
              {
                startDate: '7daysAgo',endDate: 'today'
              }
            ],"metrics": [
          {
            "expression": "ga:sessions"
          }
        ],"dimensions": [
            { "name": "ga:date" }
        ]
          }
        ]
      }
    }).then(displayResults,console.error.bind(console));
  }

 function displayResults(response) {
   
var formattedJson = JSON.stringify(response.result,null,2);


window.parent.postMessage({formattedJson:(formattedJson),userEmail:(userEmail),userId:(userId),fullName:(fullName),firstName:(firstName),lastName:(lastName),idToken:(idToken),request:(request)},"https://www.mywebsite.com"); 
  }



</script>

<!-- Load the JavaScript API client and Sign-in library. -->
<script src="https://apis.google.com/js/client:platform.js"></script>

</body>
</html>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)