Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用谷歌API获得用户生日_Php_Api_Get_Social Media - Fatal编程技术网

Php 使用谷歌API获得用户生日

Php 使用谷歌API获得用户生日,php,api,get,social-media,Php,Api,Get,Social Media,我正在使用谷歌API帮助用户登录我的网站。在使用API登录期间,我可以提取他们的姓名、地区、个人资料图片、性别和ID,但我无法获取他们的生日 我该如何用API来庆祝他们的生日 守则: session_start(); $google_client_id = 'xx'; $google_client_secret = 'xx'; $google_redirect_url = 'xx'; $google_developer_key = 'xx'; require_onc

我正在使用谷歌API帮助用户登录我的网站。在使用API登录期间,我可以提取他们的姓名、地区、个人资料图片、性别和ID,但我无法获取他们的生日

我该如何用API来庆祝他们的生日

守则:

session_start();
$google_client_id       = 'xx';
$google_client_secret   = 'xx';
$google_redirect_url    = 'xx'; 
$google_developer_key   = 'xx';

require_once 'Google_Client.php';
require_once 'contrib/Google_Oauth2Service.php';

$gClient = new Google_Client();
$gClient->setApplicationName('xx');
$gClient->setClientId($google_client_id);
$gClient->setClientSecret($google_client_secret);
$gClient->setRedirectUri($google_redirect_url);
$gClient->setDeveloperKey($google_developer_key);
$gClient->setScopes(array('email', 'https://www.googleapis.com/auth/plus.login'));
$google_oauthV2 = new Google_Oauth2Service($gClient);
if (isset($_GET['code'])) 
{ 
    $gClient->authenticate($_GET['code']);
    $_SESSION['token'] = $gClient->getAccessToken();
}

if (isset($_SESSION['token'])) 
{ 
    $gClient->setAccessToken($_SESSION['token']);
}
if ($gClient->getAccessToken()) 
{   
      $user                          = $google_oauthV2->userinfo->get();
      $user_google_id                = $user['id'];
      $user_name                     = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_first_name           = filter_var($user['given_name'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_last_name                = filter_var($user['family_name'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_gender               = filter_var($user['gender'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_country                  = filter_var($user['locale'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_age                  = filter_var($user['birthday'], FILTER_SANITIZE_SPECIAL_CHARS);
      $user_email                    = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
      $profile_url               = filter_var($user['link'], FILTER_VALIDATE_URL);
      $profile_image_url             = filter_var($user['picture'], FILTER_VALIDATE_URL);
      $user_image                    = "$profile_image_url?sz=150";
      $_SESSION['token']             = $gClient->getAccessToken();  
}
请参见此处:。总之:您必须请求具有特定作用域的访问令牌,例如
https://www.googleapis.com/auth/plus.login
并且用户必须已将其生日信息设置为
public