- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Oauth 2.0 与 Google Analytics 一起开发 WP 插件。
我的所有身份验证和数据提取工作正常,除了这个问题:我第一次获得新的 Google 授权代码(例如:“4/-xbSbg...”)并进行身份验证,然后尝试调用新的 Google_AnalyticsService() 对象,它抛回错误:
“Google_Exception”消息“通过身份验证后无法添加服务”
这是第 109 行:http://code.google.com/p/google-api-php-client/source/browse/trunk/src/apiClient.php?r=258
一旦我刷新调用此代码的页面,它就可以正常工作 - 即,check_login() 的第一个分支没问题,但身份验证调用无法正常工作。
您看到代码似乎在提示,因为我首先进行了身份验证,并且消息说我不应该这样做。评论和代码真的让我搞不清楚我的问题是什么(登录代码还不是很干净,我意识到)。
重要说明:我正在为已安装的应用程序使用 Google 身份验证,因此我们要求用户提供授权代码,并使用它来获取授权 token 。
get_option()、set_option() 和 update_option() 是 WP 原生函数,不是问题的一部分
这是我的代码:
class GoogleAnalyticsStats
{
var $client = false;
function GoogleAnalyticsStats()
{
$this->client = new Google_Client();
$this->client->setClientId(GOOGLE_ANALYTICATOR_CLIENTID);
$this->client->setClientSecret(GOOGLE_ANALYTICATOR_CLIENTSECRET);
$this->client->setRedirectUri(GOOGLE_ANALYTICATOR_REDIRECT);
$this->client->setScopes(array(GOOGLE_ANALYTICATOR_SCOPE));
// Magic. Returns objects from the Analytics Service instead of associative arrays.
$this->client->setUseObjects(true);
}
function checkLogin()
{
$ga_google_authtoken = get_option('ga_google_authtoken');
if (!empty($ga_google_authtoken))
{
$this->client->setAccessToken($ga_google_authtoken);
}
else
{
$authCode = get_option('ga_google_token');
if (empty($authCode)) return false;
$accessToken = $this->client->authenticate($authCode);
$this->client->setAccessToken($accessToken);
update_option('ga_google_authtoken', $accessToken);
}
return true;
}
function getSingleProfile()
{
$analytics = new Google_AnalyticsService($this->client);
}
}
最佳答案
您需要将 $analytics = new Google_AnalyticsService($this->client);
移动到 function GoogleAnalyticsStats()
中,最好将 $analytics 变成一个成员变量.
class GoogleAnalyticsStats
{
var $client = false;
var $analytics = false;
function GoogleAnalyticsStats()
{
$this->client = new Google_Client();
$this->client->setClientId(GOOGLE_ANALYTICATOR_CLIENTID);
$this->client->setClientSecret(GOOGLE_ANALYTICATOR_CLIENTSECRET);
$this->client->setRedirectUri(GOOGLE_ANALYTICATOR_REDIRECT);
$this->client->setScopes(array(GOOGLE_ANALYTICATOR_SCOPE));
// Magic. Returns objects from the Analytics Service instead of associative arrays.
$this->client->setUseObjects(true);
$this->analytics = new Google_AnalyticsService($this->client);
}
...
现在,您可以从 getSingleProfile
中调用分析 API。
关于google-analytics - 消息为 'Cant add services after having authenticated' 的“Google_Exception”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12397815/
最近,我收到了一个项目要求,即从某个页面将数据发送到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
我是一名优秀的程序员,十分优秀!