两次调用谷歌客户端给出致命错误

时间:2014-07-30 16:07:21

标签: php google-login

我有一个简单的脚本试图登录并注册谷歌,但为此我需要有两个不同的网址。应将其重定向到login.php,将其重定向到register.php。我没有办法如何做到这一点,所以我只是复制了谷歌客户端文件夹,其中保留了所有配置文件,我重命名了它,并将重定向网址更改为register.php,一个更改为login.php。我认为调用文件两次对我来说没问题,但是没有给出致命的错误。错误是

<b>Fatal error</b> :  Cannot redeclare class Google_Exception in E:\wordpress\InstantWP_4.3.1\iwpserver\htdocs\shoprang\name2\Google_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 个答案:

答案 0 :(得分:3)

它如此简单,你将文件包括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客户端库文件时,它会尝试重新声明该类,因此您会收到该错误。

答案 1 :(得分:1)

上面的答案是说你再次宣布谷歌课程。只需删除其中的两个。

  require_once 'name2/Google_Client.php';
    require_once 'name2/contrib/Google_Oauth2Service.php';

希望这有助于你

相关问题