问题描述
首先我是这个话题的新手,所以我希望我的问题不是太愚蠢.
first of all I am new to this topic, so I hope my question is not too stupid.
我希望我的网站可以通过 PHP 访问 Google Analytics(分析)指标.我遵循了来自谷歌的描述的每一步.不幸的是,当我将所有内容上传到我的服务器并尝试运行测试站点时,我总是收到以下错误消息:
I want my website to have PHP access to Google Analytics metrics. I followed every step of this description from google. Unfortunately when I upload everything on my server and try to run the test-site, I always get the following error-message:
致命错误:未捕获的异常异常",消息为此库"必须通过 Composer 或下载完整包安装.看说明在https://github.com/google/google-api-php-client#installation.'在/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php:14堆栈跟踪:#0/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(8):require_once() #1/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(104):getService() #2 {main} 被抛出/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php第 14 行
因此,Google 客户端库的嵌入显然有问题.在错误消息中,它说我必须使用 Composer,但在 GitHub 文档中他们说,手动下载也可以.我认为最终这应该没有任何区别吗?我不熟悉 composer 或 GitHub,这就是我手动下载它的原因.
So apparently there is something wrong with the embedding of the Google client library. In the error message it says I have to use Composer, but in the GitHub documentation they say, manual download would be fine as well. I think in the end this shouldn't make any difference? I am not familiar with composer or GitHub, this is why i downloaded it manually.
我把它上传到了服务器上,并把它放到了与 HelloAnalytics.php 相同的目录中.我通过
I uploaded it on the server and put it into the same directory like the HelloAnalytics.php. I address it in HelloAnalytics.php via
require_once 'google-api-php-client-master/src/Google/autoload.php'
推荐答案
从表面上看,您使用了错误的自动加载器.
From the looks of it you are using the wrong autoloader.
src/Google/autoload.php
寻找 Composer 自动加载器,如果它不存在,它会抛出你得到的异常.由于您没有使用 Composer 进行安装,因此未找到并抛出该异常.
src/Google/autoload.php
looks for the composer autoloader and if it doesn't exist it throws the exception you are getting. Since you didn't install using Composer it is not found and that exception is thrown.
如果您使用 git 克隆存储库,您将拥有正确的 SPL 自动加载器.如果您下载软件包,它会使用 Composer 自动加载器.
If you clone the repository using git you will have the correct SPL autoloader. If you download the package it uses the composer autoloader.
尝试使用以下方法下载:
Try downloading using:
git clone -b v1-master https://github.com/google/google-api-php-client.git
或者切换到 v1-master 分支并使用 this 自动加载器.您将看到 master
分支和 v1-master
分支之间的文件有所不同.
Or switch to the v1-master branch and use this autoloader instead. You will see that file differs between the master
branch and the v1-master
branch.
这篇关于为 Google Analtics PHP 安装 Google 客户端库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!