我有一个巨大的问题,谷歌或 php 绝对没有返回错误。
我已经编写了一个谷歌客户端 oauth2 连接模型,当我在我的 Mac 上的开发环境中运行它时它可以完美运行(我没有使用简单的本地主机,它实际上是我用来镜像生产的流浪者尽可能多的服务器),但是当我将其推送到生产环境时它不起作用。
它只是没有返回任何错误。该代码到达我从 Google 获得身份验证代码的部分,它挂在我试图将其交换为令牌的部分( $client->authenticate($auth_code) )。
我真的不知道我做错了什么,因为在开发站点上一切正常,没有错误(顺便说一下,它有一个公共链接,我尝试从不同的公共 IP 地址访问它)。
当我将代码推送到实时服务器时,它就停止了身份验证。我为每个生产服务器设置了正确的 oauth 凭据,重定向 uri 是正确的。我根本不知道我做错了什么......
这是代码的一部分(我重复一遍,它可以在具有可公开访问 url 的开发服务器上完美运行):
$this->client = new Google_Client();
$this->credentials_path . '/client_secret.json'
$this->client->setAuthConfigFile($this->credentials_path . '/client_secret.json');
$this->client->setAccessType('offline');
$this->client->setRedirectUri($this->redirect_uri);
$this->client->addScope(Google_Service_Drive::DRIVE_READONLY);
$this->client->authenticate($auth_code); //this is the part where the code hangs on a live server, but works perfectly on dev
$this->token = json_encode($this->client->getAccessToken());
$this->client->setAccessToken($this->token);
$this->writeTokenToFile($this->token);
if ($this->client->isAccessTokenExpired()) {
$this->client->refreshToken($this->token);
}
$google_drive_service = new Google_Service_Drive($this->client);
任何帮助将不胜感激!