我做了一个简单的脚本,试图登录和注册谷歌,但为此我需要有两个不同的url。一个重定向到login.php
,一个重定向到register.php
。我没有办法做到这一点,所以我只是复制了所有配置文件保存的谷歌客户端文件夹,我重新命名了它,并将重定向url更改为register.php
和一个更改为login.php
。我认为调用文件两次对我来说会很好,但没有,它给了一个致命的错误。错误是
<b>Fatal error</b> : Cannot redeclare class Google_Exception in E:wordpressInstantWP_4.3.1iwpserverhtdocsshoprangname2Google_Client.php on line 407
这是我的php
<?php
require_once 'name1/Google_Client.php';
require_once 'name1/contrib/Google_Oauth2Service.php';
$client = new Google_Client();
$client->setApplicationName("Google UserInfo PHP Starter Application");
$oauth2 = new Google_Oauth2Service($client);
$authUrl = $client->createAuthUrl();
echo $authUrl."<br>";
require_once 'name2/Google_Client.php';
require_once 'name2/contrib/Google_Oauth2Service.php';
$cliente = new Google_Client();
$cliente->setApplicationName("Google UserInfo PHP Starter Application");
$oauth2e = new Google_Oauth2Service($client);
$authUrle = $client->createAuthUrle();
echo $authUrle;
?>
请帮助我,因为我是初学者登录api与谷歌。提前感谢
这是如此如此简单,你包括文件2次。即使你认为你有require_once
但是位置不同所以它们再次被包含
删除这些
require_once 'name2/Google_Client.php'; //remove this
require_once 'name2/contrib/Google_Oauth2Service.php'; // and this
因为这两个文件已经包含在上面
require_once 'name1/Google_Client.php';
require_once 'name1/contrib/Google_Oauth2Service.php';
当第二次包含Google Client库文件时,它会尝试重新声明类,因此您会得到该错误。
上面的答案说明您再次声明google类。只需一次删除其中两个。
require_once 'name2/Google_Client.php';
require_once 'name2/contrib/Google_Oauth2Service.php';
希望这对你有帮助