未定义类型“Google_Service_Oauth2”intelephense(1009)PHP

问题描述 投票:0回答:2

我目前使用命名空间修改我的 php 脚本。我已经完成了脚本,但 Google API 包有问题

// create Client Request to access Google API
        $client = new \Google_Client(); => THIS ONE WORKS
        $client->setClientId($clientID);
        $client->setClientSecret($clientSecret);
        $client->setRedirectUri($redirectUri);
        $client->addScope("email");
        $client->addScope("profile");

        $accessToken = $key;

        // Get $id_token via HTTPS POST.
        try{
            $arrToken = $client->setAccessToken($accessToken);
            // get profile info
            $google_oauth = new \Google_Service_Oauth2($client); => IT DOESNT
            $google_account_info = $google_oauth->userinfo->get();
            $checkEmail =  $google_account_info->email;
            $name =  $google_account_info->name;
            $googleId = $google_account_info->id;           
        }

这是错误

未定义类型“Google_Service_Oauth2”intelephense(1009)

如果我不使用命名空间,则没有问题。这个真的很奇怪。

php
2个回答
1
投票

试试这个:

改变

$client = new \Google_Client();
$client->setClientId($clientID);

改变

$google_oauth = new \Google_Service_Oauth2($client)
$google_oauth = new Google\Service\Oauth2($client);


0
投票

我也有这个问题

$user = (new Google_Service_Oauth2($client))->userinfo->get();

未定义类型“Google_Service_Oauth2”.intelephense(P1009)

© www.soinside.com 2019 - 2024. All rights reserved.