I am trying to present some basic data from our Google Analytics accounts directly on our company's backend. I am using the Google API PHP Client.
我正试图从我们的谷歌分析帐户直接在我们公司的后端提供一些基本数据。我正在使用谷歌API PHP客户机。
I have followed the Hello Analytics API tutorial but it leaves me with the obligation to connect from a browser. I need the info to be available from the server itself (without browser client connection) as I would like to automate the queries from within a Cron task.
我已经学习了Hello Analytics API教程,但是它让我有义务从浏览器连接。我需要从服务器本身(没有浏览器客户端连接)获得信息,因为我希望在Cron任务中自动执行查询。
Is what I want to do possible? Am I using the correct PHP API? Is there a different way to get back GA data?
我想做的事情可能吗?我是否使用了正确的PHP API?有不同的方法来获取GA数据吗?
4 个解决方案
#1
3
Why won't you replace your google analytics service with something like Piwik!
为什么你不能用像Piwik这样的东西来代替谷歌分析服务呢!
#2
2
I skimmed through the links you provided and near as I can tell, it doesn't obligate you to connect from a browser. First off, are you sure you looked at the "php" tab in that tutorial? The walkthrough uses browser interaction, but you can easily make it do something else instead of output to the browser.. I'm guessing maybe 2.6 might be where you got confused...but that's just an example of prompting the user to login, under the assumption that you are making a web interface. For your purposes, you would be authenticating with 2.4, and as far as 2.6 is concerned, you could have your script do something else if that condition is true (like log a "failed to connect" error). And instead of printResults
echoing out stuff (because the tutorial assumes browser interface) you could do something else with it, like write to a db or something. IOW I don't see anything in that tutorial that requires browser interaction, other than they just did that as an example for the sake of the tutorial.
我浏览了您提供的链接,并且我可以看出,它并没有要求您从浏览器连接。首先,您确定在本教程中查看了“php”选项卡吗?该演练使用浏览器交互,但您可以轻松地让它做其他事情,而不是输出到浏览器。我猜2.6可能是你们搞不懂的地方。但这只是一个提示用户登录的例子,假设您正在创建一个web界面。出于您的目的,您将使用2.4进行身份验证,就2.6而言,如果条件为真,您可以让您的脚本执行其他操作(如日志a“未能连接”错误)。除了重复使用printResults(因为本教程假设使用浏览器界面)之外,您还可以使用它做一些其他的事情,比如写入数据库或其他东西。目前为止,我没有看到任何需要浏览器交互的教程,除了作为本教程的示例。
#3
2
The answer has been given elsewhere by an actual genius, @rkarbowski.
真正的天才@rkarbowski在别处给出了答案。
Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?
服务应用程序和谷歌分析API V3:服务器对服务器OAuth2身份验证?
I believe if you follow the Hello Analytics API Tutorial and then read @rkarbowski's answer, and especially the update, carefully, you will be able to make it work. I have, and I am no genius.
我相信,如果您遵循Hello Analytics API教程,然后阅读@rkarbowski的答案,特别是更新,仔细,您将能够使它工作。我有,我不是天才。
#4
0
You can use the browser to connect to the app and execute the script. (If you followed the Hello tutorial and all is working well)
您可以使用浏览器连接到应用程序并执行脚本。(如果您学习了Hello教程,并且一切正常)
Then have the script port the results into Excel or a PDF and email it out.
然后将脚本移植到Excel或PDF文件中,并通过电子邮件发送出去。
I have several crons that run daily using the GA API and kick out emails of daily stats etc.
我有几个crons每天运行使用GA API和踢出电子邮件的每日统计等。
You could theoretically build a PHP application that calls the API but it would much more work than just running the script on a browser.
理论上,您可以构建一个调用API的PHP应用程序,但这比在浏览器上运行脚本要多得多。
#1
3
Why won't you replace your google analytics service with something like Piwik!
为什么你不能用像Piwik这样的东西来代替谷歌分析服务呢!
#2
2
I skimmed through the links you provided and near as I can tell, it doesn't obligate you to connect from a browser. First off, are you sure you looked at the "php" tab in that tutorial? The walkthrough uses browser interaction, but you can easily make it do something else instead of output to the browser.. I'm guessing maybe 2.6 might be where you got confused...but that's just an example of prompting the user to login, under the assumption that you are making a web interface. For your purposes, you would be authenticating with 2.4, and as far as 2.6 is concerned, you could have your script do something else if that condition is true (like log a "failed to connect" error). And instead of printResults
echoing out stuff (because the tutorial assumes browser interface) you could do something else with it, like write to a db or something. IOW I don't see anything in that tutorial that requires browser interaction, other than they just did that as an example for the sake of the tutorial.
我浏览了您提供的链接,并且我可以看出,它并没有要求您从浏览器连接。首先,您确定在本教程中查看了“php”选项卡吗?该演练使用浏览器交互,但您可以轻松地让它做其他事情,而不是输出到浏览器。我猜2.6可能是你们搞不懂的地方。但这只是一个提示用户登录的例子,假设您正在创建一个web界面。出于您的目的,您将使用2.4进行身份验证,就2.6而言,如果条件为真,您可以让您的脚本执行其他操作(如日志a“未能连接”错误)。除了重复使用printResults(因为本教程假设使用浏览器界面)之外,您还可以使用它做一些其他的事情,比如写入数据库或其他东西。目前为止,我没有看到任何需要浏览器交互的教程,除了作为本教程的示例。
#3
2
The answer has been given elsewhere by an actual genius, @rkarbowski.
真正的天才@rkarbowski在别处给出了答案。
Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?
服务应用程序和谷歌分析API V3:服务器对服务器OAuth2身份验证?
I believe if you follow the Hello Analytics API Tutorial and then read @rkarbowski's answer, and especially the update, carefully, you will be able to make it work. I have, and I am no genius.
我相信,如果您遵循Hello Analytics API教程,然后阅读@rkarbowski的答案,特别是更新,仔细,您将能够使它工作。我有,我不是天才。
#4
0
You can use the browser to connect to the app and execute the script. (If you followed the Hello tutorial and all is working well)
您可以使用浏览器连接到应用程序并执行脚本。(如果您学习了Hello教程,并且一切正常)
Then have the script port the results into Excel or a PDF and email it out.
然后将脚本移植到Excel或PDF文件中,并通过电子邮件发送出去。
I have several crons that run daily using the GA API and kick out emails of daily stats etc.
我有几个crons每天运行使用GA API和踢出电子邮件的每日统计等。
You could theoretically build a PHP application that calls the API but it would much more work than just running the script on a browser.
理论上,您可以构建一个调用API的PHP应用程序,但这比在浏览器上运行脚本要多得多。