1 回答

TA貢獻1850條經驗 獲得超11個贊
OP和@user9156598,這是對我有用的解決方案。
$oauth = new Google_Service_Oauth2($googleClient->GetClient());
$userProfile = $oauth->userinfo->get();
$output = "<p>Name: " . $userProfile['name'] . '</p>';
$output = $output . "<p>Family Name: " . $userProfile['familyName'] . '</p>';
$output = $output . "<p>Given Name: " . $userProfile['givenName'] . '</p>';
$output = $output . "<p>Gender: " . $userProfile['gender'] . '</p>';
$output = $output . "<p>Email Address: " . $userProfile['email'] . '</p>';
$output = $output . "<p>Verified Email Address: " . $userProfile['verifiedEmail'] . '</p>';
$output = $output . "<p>Picture: " . $userProfile['picture'] . '</p>';
print($output);
谷歌客戶端構造函數:
$this->m_client = new Google_Client();
$this->m_client->setApplicationName("Local Social Meetups");
$this->m_client->setClientId(GOOGLE_CLIENT_ID);
$this->m_client->setClientSecret(GOOGLE_CLIENT_SECRET);
$this->m_client->setIncludeGrantedScopes(true);
$this->m_client->setAccessType('offline');
$this->m_client->setApprovalPrompt("force");
$this->m_client->setIncludeGrantedScopes(true);
// Set the scope of information that the application has access to. In
// this case it's just the users profile.
$scopes = array(
Google_Service_Oauth2::USERINFO_PROFILE,
Google_Service_Oauth2::USERINFO_EMAIL
);
$this->m_client->setScopes($scopes);
// The redirection Url that is used by Google after authentication.
$this->m_client->setRedirectUri(GOOGLE_REDIRECT_URL);
if (isset($_SESSION['googleAccessToken']))
{
$this->m_client->setAccessToken($_SESSION['googleAccessToken']);
}
$this->m_oauth = $this->m_client->getOAuth2Service();
- 1 回答
- 0 關注
- 88 瀏覽
添加回答
舉報