我目前使用命名空间修改我的 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)
如果我不使用命名空间,则没有问题。这个真的很奇怪。
试试这个:
改变
$client = new \Google_Client();
到$client->setClientId($clientID);
改变
$google_oauth = new \Google_Service_Oauth2($client)
到$google_oauth = new Google\Service\Oauth2($client);
我也有这个问题
$user = (new Google_Service_Oauth2($client))->userinfo->get();
未定义类型“Google_Service_Oauth2”.intelephense(P1009)