如何使用 Google Analytics (rga) 编织动态报告
How to knit dynamic reports with Google Analytics (rga)
我正在使用 rga 从 Google Analytics 获取一些数据。来自回购:
The principle of this package is to create an instance of the API Authentication, which is a S4/5-class (utilizing the setRefClass). This instance then contains all the functions needed to extract data, and all the data needed for the authentication and reauthentication. The class is in essence self sustaining.
包使用以下方法创建并保存本地实例:
rga.open(instance="ga", where="~/ga.rga")
然而,当我尝试编织时,我收到一个错误消息,指出未找到 ga
对象(实例是什么)。当我 运行 RStudio 中的块时代码有效,但是我相信错误与这方面有关:
[The command above] will check if the instance is already created, and if it is, it'll prepare the token. If the instance is not created [...] it will redirect the client to a browser for authentication with Google.
我的猜测是 knitr 无法执行最后一步,因此永远不会创建该对象。
我怎样才能完成这项工作?我在想可能有一种方法可以加载本地 ga.rga 文件以绕过浏览器身份验证。
您可以通过传递可以从 Google API 控制台获取的客户端 ID 和客户端密钥来绕过浏览器身份验证。在开发环境中保存本地授权文件总是有风险的。您可以试试这段代码,它使用 Google API 并且还保存了本地实例 -
rga.open(instance = "ga",
client.id = "<contains apps.googleusercontent.com>",
client.secret =<your secret key>, where ="~/ga.rga" )
还要确保在 Google API 控制台
中启用了桌面选项设置
我正在使用 rga 从 Google Analytics 获取一些数据。来自回购:
The principle of this package is to create an instance of the API Authentication, which is a S4/5-class (utilizing the setRefClass). This instance then contains all the functions needed to extract data, and all the data needed for the authentication and reauthentication. The class is in essence self sustaining.
包使用以下方法创建并保存本地实例:
rga.open(instance="ga", where="~/ga.rga")
然而,当我尝试编织时,我收到一个错误消息,指出未找到 ga
对象(实例是什么)。当我 运行 RStudio 中的块时代码有效,但是我相信错误与这方面有关:
[The command above] will check if the instance is already created, and if it is, it'll prepare the token. If the instance is not created [...] it will redirect the client to a browser for authentication with Google.
我的猜测是 knitr 无法执行最后一步,因此永远不会创建该对象。
我怎样才能完成这项工作?我在想可能有一种方法可以加载本地 ga.rga 文件以绕过浏览器身份验证。
您可以通过传递可以从 Google API 控制台获取的客户端 ID 和客户端密钥来绕过浏览器身份验证。在开发环境中保存本地授权文件总是有风险的。您可以试试这段代码,它使用 Google API 并且还保存了本地实例 -
rga.open(instance = "ga",
client.id = "<contains apps.googleusercontent.com>",
client.secret =<your secret key>, where ="~/ga.rga" )
还要确保在 Google API 控制台
中启用了桌面选项设置