此Google登录代码可以安全使用吗?如果没有,您将添加/更改什么?
据我所知,最新的API需要不能使用的composer,因此我在Internet上发现了更老的版本。
require_once '../common/classes/GoogleAPI/autoload.php';
$client = new Google_Client();
$client->setApplicationName("MyCMS");
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri('http://localhost/myCMS/operations/loginGoogleCallback.php');
$client->setScopes('https://www.googleapis.com/auth/userinfo.profile');
$client->setAccessType('offline');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
if (! isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$oAuth = new Google_Service_Oauth2($client);
$userData = $oAuth->userinfo_v2_me->get();
print_r($userData);
}