1
當谷歌認證的谷歌Analytics(分析)我想獲得用戶的電子郵件ID,以及是否有可能做到這一點,所以我怎麼能解決這個谷歌Analytics(分析)PHP API - 獲取用戶電子郵件
下面是我的代碼用於驗證並保存access_token
$scope =implode(' ', array(Google_Service_Calendar::CALENDAR_READONLY,Google_Service_Analytics::ANALYTICS_READONLY));
$this->client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/google/callback');
$this->client->addScope($scope);
$this->client->setAccessType("offline");
// Handle authorization flow from the server.
if (!isset($_GET['code'])) {
$auth_url = $this->client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$this->client->authenticate($_GET['code']);
$_SESSION['access_token'] = $this->client->getAccessToken();
if (isset($_SESSION['access_token']['refresh_token'])) {
$this->googledbsave_model->create_google_cred($_SESSION['id'], $_SESSION['access_token']);
if($_SESSION['id']==19){
$access_token = $_SESSION['access_token'];
$update_token = array(
'access_token' => $access_token['access_token'],
'token_type' => $access_token['token_type'],
'expires_in' => $access_token['expires_in'],
'created' => $access_token['created']
);
$get_prof = $this->googledbsave_model->update_subadmin($_SESSION['id'], $update_token);
}
} else {
$this->googledbsave_model->create_google_cred($_SESSION['id'], $_SESSION['access_token']);
$this->revokeToken();
$_SESSION['has_error'] = 1;
$_SESSION['error_message'] = "Cannot Syncronise Account Properly... Please Authenticate Again";
}
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/google/getProfileIDs';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
到目前爲止你做了什麼?沒有看到我們無法幫助你。請分享一些你寫的代碼 –
我已經更新了這個問題 – Fawaz