dongshengyin0147 2015-08-19 04:05
浏览 36
已采纳

将Google API的Analytics Client Library PHP集成到Symfony2中

I have successfully followed through the following Google article, https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php and setup a basic php script for extracting Analytics data. It was quite easy :-)

I am now trying to integrate this code into my Symfony2 project. Now it seems that the library is written in an ancient style, no namespacing and filenames are different to that of the class in them. Can anyone help me on how I can integrate it into my symfony project? I have loaded in the git repository via composer with the follwoing:

"repositories": [
        {
            "type": "package",
            "package": {
                "name": "google/google-api-php-client",
                "version": "1.1.4",
                "dist": {
                    "url": "https://github.com/google/google-api-php-client/archive/1.1.4.zip",
                    "type": "zip",
                    "reference": "1.1.4"
                }
            }
        }
    ],

But the issue is all of the autoloading etc.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongyi0210 2015-08-19 08:10
    关注

    The library has a composer.json file and is registered in packagist, so you just need to add "google/apiclient": "1.1.4" in your composer's require section, and composer will handle the autoloading.

    Then to integrate it to Symfony the right way, please read the doc here to learn how to register your own services in your services.yml file.

    Define your application name and your key as parameters in your parameters.yml to reuse them in your service definitions.

    Define a service for each class you instanciate (e.g. a service for Google_Client, Google_Service_Analytics, Google_Auth_AssertionCredentials, ...) with the right dependencies on other services and/or parameters.

    Note: I've found those bundle on knpbundles: isometriks/GoogleApiBundle and Happyr/GoogleApiBundle, they may help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测