开发者

gmail oauth imap zend retrieve from gmail instead of session

开发者 https://www.devze.com 2023-02-22 07:14 出处:网络
Im planning to use google oauth IMAP to sign up for my website. Im using zend framework for the same. http://code.google.com/p/google-mail-xoauth-tools/wiki/PhpSampleCode

Im planning to use google oauth IMAP to sign up for my website. Im using zend framework for the same. http://code.google.com/p/google-mail-xoauth-tools/wiki/PhpSampleCode Also im suing 3 legged approach to sign up When i go through the sample threelegged.php. I find that i t has email address inbox and he keeps it in a session and goes to access the gmail account and once he returns back he retireves the email id from the session

$email_address = $_SESSI开发者_开发百科ON['email_address'];

Line No.121

$config = new Zend_Oauth_Config();

$config->setOptions($options);

$config->setToken($accessToken);

$config->setRequestMethod('GET');

$url = 'https://mail.google.com/mail/b/' . $email_address . '/imap/';

My requirement is i do not want to have email address to be kept in session instead i want the given the gmail address to be retrieved in $email address. How can i do that ? Is any function supporting it in Zend framework?


http://sites.google.com/site/oauthgoog/Home/emaildisplayscope

You will need to include the authorization url with your other urls you are asking permission to get data from: https://www.googleapis.com/auth/userinfo.email

Then when you actually get the authorized token you can do it like this:

// Get access token from session after authorization process is complete.
$accessToken = unserialize($_SESSION['ACCESS_TOKEN']);

// Retrieve email address using Access Token
$erequest = $accessToken->getHttpClient($options);
$erequest->setUri('https://www.googleapis.com/userinfo/email');
$erequest->setMethod(Zend_Http_Client::GET);
$ereturn = $erequest->request();
parse_str($ereturn->getBody(), $earray);
$email_address = $earray['email'];

// Retrieve mail using Access Token
$config = new Zend_Oauth_Config();
$config->setOptions($options);
$config->setToken($accessToken);
$config->setRequestMethod('GET');
$url = 'https://mail.google.com/mail/b/' .
   $email_address . 
   '/imap/';

This is after authenticating a token for accessing the data. Then the email address can be used for your mail request or anything else that requires the email address.

0

精彩评论

暂无评论...
验证码 换一张
取 消