Closed Huang-junsen closed 4 months ago
public function getUserInfo() { $this->getToken();
$headers = ['Authorization : Bearer ' . $this->token['access_token']]; $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers); }
改为 下面的
$headers = array( 'Authorization: Bearer ' . $this->token['access_token'], );
// 创建请求上下文 $context = stream_context_create(array( 'http' => array( 'header' => $headers, ), )); try { $data = file_get_contents(self::API_BASE . 'oauth2/v2/userinfo', false, $context); // 检查响应是否成功 if ($data !== false) { return json_decode($data, true); } else { throw new \Exception("请求失败 " . $data); } }catch (Exception $exception){ throw new \Exception("异常 " . $exception); }
您需要拥有一个海外的服务哦,否则不可以调用google的登录接口,所以导致访问超时
public function getUserInfo() { $this->getToken();
改为 下面的
$headers = array( 'Authorization: Bearer ' . $this->token['access_token'], );