我是Google Analytics API的「新手」,我試圖讓「Hello Analytics」示例正常工作。Hello Analytics示例生成403錯誤
我跟着their steps 來創建測試網頁,但我沒有結果。
當我進入我的網頁時,我看到標題,「登錄」按鈕和下面顯示結果的文本區域。當我按「登錄」時,這似乎工作;該按鈕變爲「已登錄」。但是,沒有結果顯示。
我使用的是FireFox,所以我右鍵單擊文本區域並選擇「檢查元素」;這表明此錯誤消息:
對象{結果:對象,身體: 「{ 」錯誤「:{ 」代碼「:403,...」, 頭:對象,狀態:403,狀態文本: 「紫禁城」 }
我認爲這是一個權限錯誤,但不知道如何糾正它。
這裏是我的文件HelloAnalytics.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Analytics Reporting API V4</title>
<meta name="google-signin-client_id" content="959582115031-ardmn5vsir7kbcp0dme4d4n1p45bd649.apps.googleusercontent.com">
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly">
</head>
<body>
<h1>Hello Analytics Reporting API V4</h1>
<p>
<!-- The Sign-in button. This will run `queryReports()` on success. -->
<div class="g-signin2" data-onsuccess="queryReports"></div>
</p>
<!-- The API response will be printed here. -->
<textarea cols="80" rows="20" id="query-output"></textarea>
<script>
// Replace with your view ID.
var VIEW_ID = '92320289';
// Query the API and print the results to the page.
function queryReports() {
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'
}
]
}
]
}
}).then(displayResults, console.error.bind(console));
}
function displayResults(response) {
var formattedJson = JSON.stringify(response.result, null, 2);
document.getElementById('query-output').value = formattedJson;
}
</script>
<!-- Load the JavaScript API client and Sign-in library. -->
<script src="https://apis.google.com/js/client:platform.js"></script>
</body>
</html>
我需要了解如何使用谷歌Analytics(分析)API做簡單的查詢。
你是在本地運行還是在服務器上運行? – sideroxylon
如何在谷歌分析API中進行分頁? –