2012-03-31 123 views
0

我使用Zend Gmail Oauth 1.0实现使用Gmail功能登录。 成功验证后,如何获得已验证的用户个人资料,特别是用户唯一的Gmail身份证?这里是代码:Zend Gmail Oauth:如何获取经过身份验证的用户配置文件?

$THREE_LEGGED_SCOPES = array('https://mail.google.com/', 
    'https://www.google.com/m8/feeds'); 

$options = array(
     'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 
     'version' => '1.0', 
     'consumerKey' => $THREE_LEGGED_CONSUMER_KEY, 
     'consumerSecret' => $THREE_LEGGED_CONSUMER_SECRET_HMAC, 
     'callbackUrl' => getCurrentUrl(), 
     'requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken', 
     'userAuthorizationUrl' => 'https://www.google.com/accounts/OAuthAuthorizeToken', 
     'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken' 
    ); 

    if ($THREE_LEGGED_SIGNATURE_METHOD == 'RSA-SHA1') { 
     $options['signatureMethod'] = 'RSA-SHA1'; 
     $options['consumerSecret'] = new Zend_Crypt_Rsa_Key_Private(
      file_get_contents(realpath($THREE_LEGGED_RSA_PRIVATE_KEY))); 
    } else { 
     $options['signatureMethod'] = 'HMAC-SHA1'; 
     $options['consumerSecret'] = $THREE_LEGGED_CONSUMER_SECRET_HMAC; 
    } 

    $consumer = new Zend_Oauth_Consumer($options); 

    /** 
    * When using HMAC-SHA1, you need to persist the request token in some way. 
    * This is because you'll need the request token's token secret when upgrading 
    * to an access token later on. The example below saves the token object 
    * as a session variable. 
    */ 
    if (!isset($_SESSION['ACCESS_TOKEN'])) { 
     if (!isset($_SESSION['REQUEST_TOKEN'])) { 
     // Get Request Token and redirect to Google 
     $_SESSION['REQUEST_TOKEN'] = serialize($consumer->getRequestToken(array('scope' => implode(' ', $THREE_LEGGED_SCOPES)))); 
     $consumer->redirect(); 
     } else { 
     // Have Request Token already, Get Access Token 
     $_SESSION['ACCESS_TOKEN'] = serialize($consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN']))); 
     header('Location: ' . getCurrentUrl(false)); 
     exit; 
     } 
    } else { 
     // Retrieve mail using Access Token 
     $accessToken = unserialize($_SESSION['ACCESS_TOKEN']); 
    } 

回答

0

附近,因为我可以告诉你不能。
Gmail没有api只读feed
但是如果你想要的是饲料的范围网址为:

https://mail.google.com/mail/feed/atom/ 

有一些API的与在Google Apps上下文Gmail账户工作。

相关问题