首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google登录PHP

Google登录PHP
EN

Stack Overflow用户
提问于 2019-07-27 04:31:39
回答 1查看 114关注 0票数 1

我正在添加谷歌登录到我的网站。我遵循的步骤这里没有任何问题,只有当我使用后端服务器进行身份验证得到一个错误(500个内部服务器错误)。

我正在使用下载发布说明并下载google-api-php-client-2.2.3.zip。我不确定这是否相关,但是服务器上安装的PHP版本是PHP5.2.17版本

解压缩后,文件的内容(src、供应商、composer.json等)都会被移动到我的项目的根文件夹并上传到服务器。

HTML直接从使用说明中复制和粘贴,以尽量减少我端的人为错误。

代码语言:javascript
复制
function onSignIn(googleUser) {
    var id_token = googleUser.getAuthResponse().id_token;
    // console.log(id_token);

    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'googleauth.php');
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onload = function() {
        console.log('Signed in as: ' + xhr.responseText);
    };
    xhr.send('idtoken=' + id_token);

    var profile = googleUser.getBasicProfile();
    sessionStorage.refName = profile.getId();
    // console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
    // console.log('Name: ' + profile.getName());
    // console.log('Image URL: ' + profile.getImageUrl());
    // console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}

function signOut() {
    sessionStorage.clear();
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
        console.log('User signed out.');
    });
}
代码语言:javascript
复制
<?php
    require_once 'vendor/autoload.php';

    $id_token = $_POST["idtoken"];
    echo 'test2';
?>

当我注释掉‘performs /autooload.php’文件中的代码而只让它返回" test1“时,require_once成功地执行了它的功能,并成功地登录到控制台。但是,当我运行最初由Google编写的脚本时,我会得到一个500 (内部服务器错误),并将“登录为:”登录到控制台。

这个api中有这么多文件,我发现它不可能导航。而且我也很难相信Google会以一种无法直接发挥作用的方式发布如此重要的东西。

从我的角度来看,我认为我是逐字逐句地执行指令,但有没有人对他们认为我可能误解了什么,或者我可以尝试什么不一样有任何建议?

编辑从服务器添加错误日志(用$标记替换个人信息)

代码语言:javascript
复制
$$$$$/error_log:
[25-Jul-2019 23:35:39] PHP Warning:  require_once(__DIR__/composer/autoload_real.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /$$$$$$$/vendor/autoload.php on line 5
[25-Jul-2019 23:35:39] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/usr/lib64/php:/usr/share/pear') in /$$$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 01:17:47] PHP Warning:  require_once(__DIR__/composer/autoload_real.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /$$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 01:17:47] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/usr/lib64/php:/usr/share/pear') in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 20:05:09] PHP Fatal error:  Uncaught exception 'Exception' with message 'This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation.' in /$$$$$/src/Google/autoload.php:14
Stack trace:
#0 /$$$$$/googleauth.php(3): require_once()
#1 {main}
  thrown in /$$$$$/src/Google/autoload.php on line 14
[26-Jul-2019 20:05:19] PHP Fatal error:  Uncaught exception 'Exception' with message 'This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation.' in /$$$$$/src/Google/autoload.php:14
Stack trace:
#0 /$$$$$/googleauth.php(3): require_once()
#1 {main}
  thrown in /$$$$$/src/Google/autoload.php on line 14
[26-Jul-2019 20:18:25] PHP Fatal error:  Uncaught exception 'Exception' with message 'This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation.' in /$$$$$/vendor/Google/autoload.php:14
Stack trace:
#0 /$$$$$/googleauth.php(3): require_once()
#1 {main}
  thrown in /$$$$$/vendor/Google/autoload.php on line 14
[26-Jul-2019 20:19:09] PHP Fatal error:  Uncaught exception 'Exception' with message 'This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation.' in /$$$$$/vendor/Google/autoload.php:14
Stack trace:
#0 /$$$$$/googleauth.php(3): require_once()
#1 {main}
  thrown in /$$$$$/vendor/Google/autoload.php on line 14
[26-Jul-2019 20:25:41] PHP Warning:  require_once(__DIR__/composer/autoload_real.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 20:25:41] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/usr/lib64/php:/usr/share/pear') in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 20:28:17] PHP Warning:  require_once(__DIR__/composer/autoload_real.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 20:28:17] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/usr/lib64/php:/usr/share/pear') in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 22:09:46] PHP Warning:  require_once(__DIR__/composer/autoload_real.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /$$$$$/vendor/autoload.php on line 5
[26-Jul-2019 22:09:46] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/usr/lib64/php:/usr/share/pear') in /$$$$$/vendor/autoload.php on line 5

/$$$$$/vendor/Google/error_log:
[26-Jul-2019 20:22:48] PHP Parse error:  syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /$$$$/vendor/Google/Client.php on line 18
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-27 07:37:40

我重读了API注释,结果发现PHP版本确实很重要.

要求: PHP 5.4.0或更高版本

我已经更新了服务器上使用的版本,不再收到任何错误

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57229141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档