- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用核心报告 API 进行报告。我在我的本地主机服务器上安装了 Google PHP API 客户端主机,并在我包含的 src 文件夹中创建了一个文件 HelloAnalyticsAPI.php
Google/Client.php , Google/Service/Analytics.php
文件。并使用以下详细信息
$client->setClientId('XXXXXXXXXXX.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXXXXXX');
$client->setRedirectUri('http://localhost/analytics/src/HelloAnalyticsApi.php');
$client->setDeveloperKey('XXXXXXXXXXX');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
$client->setUseObjects(true);
我在 setUseObjects 上遇到 fatal error 。错误是 fatal error :调用未定义的方法 Google_Client::setUseObjects()
。我也在我的谷歌分析后端做了一些授权。
请让我知道在我的服务器上获取报告的整个过程。因为我无法理解他们提供的 Google Analytics 开发人员指南。
最佳答案
您遇到的问题是您的客户端库有误。 Hello Analytics API 教程是使用 Code.google - google-api-php-client 上的旧库创建的不是 github 上的较新版本.
更新:由于该教程仍未更新,因此我制作了一个可能有帮助的教程。 Google Oauth2 php .下面的代码是直接从中提取的。本教程将保持最新,您可能需要检查是否有任何更改。
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("{devkey}");
$client->setClientId('{clientid}.apps.googleusercontent.com');
$client->setClientSecret('{clientsecret}');
$client->setRedirectUri('http://www.daimto.com/Tutorials/PHP/Oauth2.php');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
//For loging out.
if ($_GET['logout'] == "1") {
unset($_SESSION['token']);
}
// Step 2: The user accepted your access now you need to exchange it.
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
// Step 1: The user has not authenticated we give them a link to login
if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
// Step 3: We have access we can now create our service
if (isset($_SESSION['token'])) {
print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Analytics($client);
// request user accounts
$accounts = $service->management_accountSummaries->listManagementAccountSummaries();
foreach ($accounts->getItems() as $item) {
echo "Account: ",$item['name'], " " , $item['id'], "<br /> \n";
foreach($item->getWebProperties() as $wp) {
echo ' WebProperty: ' ,$wp['name'], " " , $wp['id'], "<br /> \n";
$views = $wp->getProfiles();
if (!is_null($views)) {
foreach($wp->getProfiles() as $view) {
// echo ' View: ' ,$view['name'], " " , $view['id'], "<br /> \n";
}
}
}
} // closes account summaries
}
print "<br><br><br>";
print "Access from google: " . $_SESSION['token'];
?>
关于php - 使用 HelloAnalyticsApi 时调用 Google Analytics 中未定义的方法 Google_Client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370951/
最近,我收到了一个项目要求,即从某个页面将数据发送到Google Analytics(分析)。我不知道该怎么做。 帐户ID和所有内容均已创建,我只想知道如何在加载某个网页时发送数据。 我一直在根据自己
我试图在此站点和其他一些站点上找到此问题的答案。但这似乎并不适合我自己。以下网址显示了有关如何同时使用GA和UA的说明。 How to use both ga.js and analytics.js?
从谷歌的文档: The analytics.js snippet is part of Universal Analytics, which is currently in public beta.
根据google的新analytics.js文档,您可以设置多个跟踪器,并通过在单独的send调用中按名称明确提及跟踪器来向其发送事件: https://developers.google.com/a
有什么办法可以让 Google Analytics 的“In-Page Analytics”显示外部链接流量? 实际上,外部链接的综合浏览量会显示在流量报告中,但不会显示在页内分析中。 我们正在使用这
我正在尝试编写一个 Google Analytics API 查询,它只返回去年每个月的每月唯一身份访问者。 This is the data I see in the Google Analytic
我们在我们的应用程序中使用 Google Analytics,但现在我们需要更改它并改用 Adobe Analytics。 在对这两种工具进行比较研究时,我现在意识到了这两种工具的优缺点和特点,
我需要您有关 Google Analytics (analytics.js) 的帮助。我在头部有第一个通用部分,效果很好: (function(i,s,o,g,r,a,m
这个问题在这里已经有了答案: Why use protocol-relative URLs at all? (5 个答案) 关闭 5 年前。 我正在阅读 https://developers.goo
将目标从Analytics(分析)导入到AdWords中,然后在Analytics(分析)中更改目标条件时,是否可以通过更改将目标“重新导入”到AdWords,还是可以自动选择? 最佳答案 更改目标值
Google最近更新了他们对开发人员的政策。 https://play.google.com/about/privacy-security/personal-sensitive/ If your ap
我正在使用google analytics api来获取数据。我正在获取数据,但我想验证两个参数,它们在特定日期范围内始终为0。我正在获取['ga:transactions']和['ga:goalCo
我使用Google API从Google Analytics(分析)获取数据,但指标与Google Analytics(分析)的网络界面不同。 即:我在2015年3月1日获得数据-它返回综合浏览量79
我安装了 Google Analytics (UA) 并将跟踪代码添加到 html 页面。我从浏览器文件中运行 html 页面:///C:/test.html 并使用谷歌调试器进行调试,它成功运行并显
我正在遵循 https://developers.google.com/analytics/devguides/collection/amp-analytics/ 的简单指南 尝试添加 Pagevie
我计划管理大约。通过为每个属性创建带有主机名过滤器的专用 View ,可以在一个属性下创建 400 个差异站点。是否有任何流程可以在不手动创建 View 和制作过滤器的情况下完成此任务? 例如:我们有
我想使用 Google Analytics API 访问 User Explorer 数据,以获取 JSON 值形式的报告。使用此 JSON 值,我可以创建用于分析的 Web 应用程序仪表板。我在此
我正在尝试使用此代码来跟踪 Google Analytics 中的事件 _trackEvent(category, action, opt_label, opt_value, opt_noni
我目前正在使用访问 token 和刷新 token 从 Google Analytics Reporting API (v4) 中提取数据。当我致力于自动从 Google Analytics 中提取数
我正在尝试根据此相关问题实现 anchor (index.html#anchor)跟踪: How to track anchor tags with Google Analytics 我使用 anch
我是一名优秀的程序员,十分优秀!