`
天梯梦
  • 浏览: 13726408 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

php 获取gmail/yahoo 联系人地址

阅读更多

gmail:

 

<?php
 
error_reporting(E_ALL);
 
$user = "****@gmail.com";
$password = "****";
 
// ref: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
 
// step 1: login
$login_url = "https://www.google.com/accounts/ClientLogin";
$fields = array(
	'Email' => $user,
	'Passwd' => $password,
	'service' => 'cp', // <== contact list service code
	'source' => 'test-google-contact-grabber',
	'accountType' => 'GOOGLE',
);
 
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$login_url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,$fields);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($curl);
 
$returns = array();
 
foreach (explode("\n",$result) as $line)
{
	$line = trim($line);
	if (!$line) continue;
	list($k,$v) = explode("=",$line,2);
 
	$returns[$k] = $v;
}
 
curl_close($curl);
 
// step 2: grab the contact list
$feed_url = "http://www.google.com/m8/feeds/contacts/$user/full?alt=json&max-results=250";
 
$header = array(
	'Authorization: GoogleLogin auth=' . $returns['Auth'],
);
 
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $feed_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
 
$result = curl_exec($curl);
curl_close($curl);
 
$data = json_decode($result);
 
$contacts = array();
 
foreach ($data->feed->entry as $entry)
{
	$contact = new stdClass();
	$contact->title = $entry->title->{'$t'};
	$contact->email = $entry->{'gd$email'}[0]->address;
 
	$contacts[] = $contact;
}
 
var_dump($contacts);
 

 

yahoo:

 

<?

require_once('class.GrabYahoo.php');

// Yahoo! Account Username
$login    = "****@yahoo.com";

// Yahoo! Account Password
$password = "****";

// Initializing Class
$yahoo  = new GrabYahoo;

/* 
Setting the desired Service 
  1. addressbook => Used to grab Yahoo! Address Book
  2. messenger => Used to grab Yahoo! Messenger List
  3. newmail => Used to grab number of new Yahoo! mails
  4. calendar => Used to grab Yahoo! Calendar entries 
*/
$yahoo->service = "addressbook";

/*
Set to true if HTTP proxy is required to browse net
  - Setting it to true will require to provide Proxy Host Name and Port number
*/
$yahoo->isUsingProxy = false;

// Set the Proxy Host Name, isUsingProxy is set to true
$yahoo->proxyHost = "";

// Set the Proxy Port Number
$yahoo->proxyPort = "";

// Set the location to save the Cookie Jar File
$yahoo->cookieJarPath = "./";

/* 
Execute the Service 
  - Require to pass Yahoo! Account Username and Password
*/
$yahooList = $yahoo->execService($login, $password);

// Printing the array generated by the Class
dump($yahooList);

/* 
Printing new mail status
  - True (1) if there is new mail(s)
  - False (0) if there is no new mail
*/
//$newMailStatus  = $yahoo->getNewMailStatus();
//echo $newMailStatus;

// Use this line to figure out any error generated during the process
echo $yahoo->errorInfo;

function dump($var)
{
  echo "<pre>";
    print_r($var);
  echo "</pre>";
}

?>
 

class.GrabYahoo.php

 

<?php
/*------------------------------------------------------
 GrabYahoo - Yahoo Service Grabber class
 
 Version 1.5, Created 05/22/2006, Updated 11/03/2010
 
 Credit for latest fix: Ovidiu
 
 This class is used to grab Yahoo services like
 Address Book, Messenger List, Number of New Mails

 Copyright (C) 2006 Ehsan Haque

 License: GPL
------------------------------------------------------*/

/**
 * GrabYahoo - Yahoo Service Grabber class
 * @package GrabYahoo
 * @license GPL
 * @copyright (C) 2006 Ehsan Haque
 * @version 1.4
 * @created 05/22/2006
 * @updated 02/06/2008
 * @author Ehsan Haque 
 */
 
class GrabYahoo
{
  /*-------------------------------------------------------
  Public Variables
  -------------------------------------------------------*/
  /**
  * Service name (1. addressbook, 2. messenger, 3. newmail, 4. calendar)
  * @public
  * @var string
  */
  var $service            = "";
  
  /**
  * Yahoo! Account Username
  * @public
  * @var string
  */
  var $login              = "";

  /**
  * Yahoo! Account Password
  * @public
  * @var string
  */  
  var $password           = "";

  /**
  * Abosolute path to save the cookie
  * Default value is DOCUMENT_ROOT
  * @public
  * @var string
  */
  var $cookieJarPath      = "";
  
  /**
  * Abosulte path to the CA Bundle file
  * SSL Certificate required to verify CA cert
  * Usually required when script ran on Localhost
  * Remote servers may not require 
  * Default value is false
  * @public
  * @var string
  */
  var $caBundleFile       = "";

  /**
  * Specifies if Proxy server required as Gateaway
  * Default value is false
  * @public
  * @var boolean
  */  
  var $isUsingProxy       = false;
                          
  /**                     
  * Proxy host name       
  * @public               
  * @var string          
  */                      
  var $proxyHost          = "";
                          
  /**                     
  * Proxy port number     
  * @public               
  * @var int             
  */                      
  var $proxyPort          = 0;

  /*-------------------------------------------------------
  Private Variables
  -------------------------------------------------------*/
  /**
  * URL to Authenticate user on Yahoo!
  * @private
  * @var string
  */
  var $authUrl            = "http://login.yahoo.com/config/login?";

  /**
  * URL for the desired Service
  * @private
  * @var string
  */                          
  var $serviceUrl         = "";

  /**
  * URL to be used by cURL
  * @private
  * @var string
  */                          
  var $url                = "";

  /**
  * User agent (used to trick Yahoo!)
  * @private
  * @var string
  */
  var $userAgent          = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";

  /**
  * Referer URL (used to trick Yahoo!)
  * @private
  * @var string
  */
  var $referer            = "http://my.yahoo.com";

  /**
  * Specifies whether output includes the header
  * @private
  * @var int
  */
  var $showHeader         = 0;

  /**
  * Specifies if cURL should follow the redirected URL
  * @private
  * @var int
  */
  var $follow             = 0;

  /**
  * Specifies number of post fields to pass
  * @private
  * @var int
  */                          
  var $numPostField       = 0;

  /**
  * Specify fields to send via POST method as key=value
  * @private
  * @var string
  */
  var $postFields         = "";

  /**
  * File where output is temporarily saved during authentication
  * @private
  * @var string
  */
  var $authOutputFile     = "";

  /**
  * Variable used by Yahoo to verify the request is valid
  * @private
  * @var string
  */
  var $crumb              = "";
  
  /**
  * File where service output is temporarily saved 
  * @private
  * @var string
  */
  var $outputFile         = "";

  /**
  * File where Cookie is temporarily saved 
  * @private
  * @var string
  */                          
  var $cookieFileJar      = "";

  /**
  * Cookie File that is read by service process
  * This carries same value as $cookieFileJar
  * @private
  * @var string
  */
  var $cookieFile         = "";

  /**
  * Specifies if Cookie is to be in header
  * @private
  * @var int
  */
  var $cookie             = 0;

  /**
  * Proxy address as proxy.host:port
  * @private
  * @var string
  */
  var $proxy              = "";

  /**
  * Error Information set by either cURL or Internal process
  * @private
  * @var string
  */
  var $errorInfo          = "";

  /**
  * Returns true if there is new mail otherwise false
  * @private
  * @var boolean
  */  
  var $newMailStatus      = false;
  
  /**
  * Sets Service URL
  * @return void
  */
  function setServiceUrl() 
  {
    if (empty($this->service))
    {
      $this->setError("provide_service");
      return false;
    }
    
    // Sets the URL depending on the choosen service
    switch ($this->service)
    {
  	  //updated by ovidiuw3b
	  case 'addressbook' : $this->serviceUrl   = "http://address.mail.yahoo.com/?_src=&VPC=print"; break;
	  //end update
	  
	  //updated by ovidiuw3b
	  case 'messenger'   : $this->serviceUrl   = "http://address.mail.yahoo.com/?_src=&VPC=print"; break;
	  //end update
	  
      case 'newmail'     : $this->serviceUrl   = "http://mail.yahoo.com/"; break;
      
      case 'calendar'    : $this->serviceUrl   = "http://calendar.yahoo.com/"; break;
    }
  }
  
  /**
  * Sets the Cookie Jar File where Cookie is temporarily saved
  * @return void
  */
  function setCookieJar()
  {
    // Sets the encrypted cookie filename using Yahoo! account username
    $this->cookieFilename = MD5($this->login);
    
    // Sets the Cookie Jar filename with an absolute path
    $this->cookieFileJar  = (!empty($this->cookieJarPath)) ? $this->cookieJarPath . "/" . $this->cookieFilename : $_SERVER['DOCUMENT_ROOT'] . "/" . $this->cookieFilename;
    
    fopen($this->cookieFileJar, "w");
  }

  /**
  * Initializes cURL session
  * @return void
  */  
  function initCurl()
  {
    $this->curlSession    = curl_init();
  }

  /**
  * Sets cURL options
  * @return boolean
  */  
  function setCurlOption() 
  {
    // Sets the User Agent  
    curl_setopt($this->curlSession, CURLOPT_USERAGENT, $this->userAgent);
    
    // Sets the HTTP Referer
    curl_setopt($this->curlSession, CURLOPT_REFERER, $this->referer);
    
    // Sets the URL that PHP will fetch using cURL
    curl_setopt($this->curlSession, CURLOPT_URL, $this->url);
    
    // Sets the number of fields to be passed via HTTP POST
    curl_setopt($this->curlSession, CURLOPT_POST, $this->numPostField);
    
    // Sets the fields to be sent via HTTP POST as key=value
    curl_setopt($this->curlSession, CURLOPT_POSTFIELDS, $this->postFields);
    
    // Sets the filename where cookie information will be saved
    curl_setopt($this->curlSession, CURLOPT_COOKIEJAR, $this->cookieFileJar);
    
    // Sets the filename where cookie information will be looked up
    curl_setopt($this->curlSession, CURLOPT_COOKIEFILE, $this->cookieFile);
    
    // Sets the option to set Cookie into HTTP header
    curl_setopt($this->curlSession, CURLOPT_COOKIE, $this->cookie);

    // Checks if the user needs proxy (to be set by user)
    if ($this->isUsingProxy) 
    { 
      // Checks if the proxy host and port is specified
      if ((empty($this->proxyHost)) || (empty($this->proxyPort)))
      { 
        $this->setError("proxy_required");
        $this->unlinkFile($this->cookieFileJar);
        return false;
      }
     
      // Sets the proxy address as proxy.host:port
      $this->proxy          = $this->proxyHost . ":" . $this->proxyPort;
    }
        
    // Sets the proxy server as proxy.host:port
    curl_setopt($this->curlSession, CURLOPT_PROXY, $this->proxy);
    
    // Sets the filename where output will be temporarily saved
    curl_setopt($this->curlSession, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt($this->curlSession, CURLOPT_FOLLOWLOCATION, $this->follow);
    
    return true;
  }

  /**
  * Executes the Service
  * @param string $login Username of user's Yahoo! Account
  * @param string $password Password of the user's Yahoo! Account
  * @return array|false
  */  
  function execService($login, $password)
  {
    $login      = trim($login);
    $password   = trim($password);
    
    if (empty($login)) 
    {
      $this->setError("provide_login");
      return false;
    }
    
    if (empty($password)) 
    {
      $this->setError("provide_pass");
      return false;
    }
    
    $this->login      = $login;
    $this->password   = $password;
    
    $this->setServiceUrl();
    
    // Instructs to authenticate user on Yahoo!
    $this->auth       = $this->doAuthentication();
    
    if ($this->auth)
    {
      // Instructs to fetch output if Authenticated
      $this->getServiceOutput();
      
      return $this->serviceOutput;
    }
  }

  /**
  * Authenticates user on Yahoo!
  * @return boolean
  */
  function doAuthentication()
  {
    // Instructs to initialize cURL session
    $this->initCurl();
    
    // Sets the URL for authentication purpose
    $this->url              = $this->authUrl;
    
    // Sets the number of fields to send via HTTP POST
    $this->numPostField     = 22;
    
    // Sets the fields to be sent via HTTP POST as key=value
    $this->postFields       = "login=$this->login&passwd=$this->password&.src=&.tries=5&.bypass=&.partner=&.md5=&.hash=&.intl=us&.tries=1&.challenge=ydKtXwwZarNeRMeAufKa56.oJqaO&.u=dmvmk8p231bpr&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.v=0&.chkP=N&.last=&.done=" . $this->serviceUrl;
    
    // Instructs to set Cookie Jar
    $this->setCookieJar();
          
    // Checks if the cURL options are all set properly
    if ($this->setCurlOption())
    {
      // Instructs to execute cURL session
      $this->execCurl();

      // Checks if any cURL error is generated
      if ($this->getCurlError())
      {
        $this->unlinkFile($this->cookieFileJar);
        $this->setError("curl_error");
        return false;
      }

      // Checks if the authentication failed, either invalid login or username is not registered
      if ((preg_match("/invalid/i", $this->outputContent)) || (preg_match("/not yet taken/i", $this->outputContent)))
      {
        // Instructs to close cURL session
        $this->closeCurl();
        
        // Unlinks the cookie file
        $this->unlinkFile($this->cookieFileJar);
        
        $this->setError("invalid_login");
        return false;
      }
      
      $this->closeCurl();
    }
    
    unset($this->outputContent);
    
    return true;
  }

  /**
  * Sets the Service Output
  * @return void
  */  
  function getServiceOutput()
  {  
    // Instructs to process the choosen service
    switch ($this->service)
    {
      case 'addressbook'    : $this->showHeader     = 0;
                              $this->getCrumb();
                              $this->serviceOutput  = $this->processAddressBook(); 
                              break;
  
      case 'messenger'      : $this->showHeader     = 0;
                              $this->getCrumb();      
                              $this->serviceOutput  = $this->processMessengerList(); 
                              break;

      case 'newmail'        : $this->showHeader     = 0;
                              $this->follow         = 1;
                              $this->serviceOutput  = $this->processNewMail();
                              break;

      case 'calendar'       : $this->showHeader     = 0;
                              $this->serviceOutput  = $this->processCalendar();
                              break;
    }
    
    $this->unlinkFile($this->cookieFileJar);
  }

  /**
  * Processes Yahoo! Address Book
  * @return array|false
  */
  function processAddressBook()
  {
    $this->initCurl();
    $this->url              = $this->serviceUrl;
    $this->numPostField     = 1;
    
	//updated by ovidiuw3b
	$this->postFields		= "VPC=print&field[allc]=1&field[catid]=0&field[style]=>detailed&submit[action_display]=Display for Printing";
	//end update
	
    $this->cookieFile       = $this->cookieFileJar;
    $this->outputFile       = "addressBook." . md5($this->login) . ".txt";
    $this->fileHandler      = fopen($this->outputFile, "w");
    
    if ($this->setCurlOption())
    {
      $this->execCurl();
	  $res=$this->outputContent;
      $this->closeCurl();
	  
	  $emailA=array();$bulk=array();$contacts=array();
		
		$res=str_replace(array('  ','	',PHP_EOL,"\n","\r\n"),array('','','','',''),$res);
		preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<div\>\<\/div\>(.+)\<\/div\>#U",$res,$bulk);
		if (!empty($bulk))
			{
			foreach($bulk[1] as $key=>$bulkName)
				{
				$nameFormated=trim(strip_tags($bulkName));
				if (preg_match('/\&nbsp\;\-\&nbsp\;/',$nameFormated)) 
					{
					$emailA=explode('&nbsp;-&nbsp;',$nameFormated);
					if (!empty($emailA[1])) $contacts[$emailA[1].'@yahoo.com']=array('first_name'=>$emailA[0],'email_1'=>$emailA[1].'@yahoo.com');
					}
				elseif (!empty($bulk[3][$key])) { $email=strip_tags(trim($bulk[3][$key])); $contacts[$email]=array('first_name'=>$nameFormated,'email_1'=>$email); }
				}
			}			
		foreach ($contacts as $email=>$name) if (!$this->isEmail($email)) unset($contacts[$email]);

		return $contacts;
    }    
  }

  /**
  * Locates and sets the value for crumb
  * @return void
  */  
  function getCrumb()
  {
    $this->initCurl();
    $this->url              = $this->serviceUrl . "?1&VPC=import_export&.rand=1238474830";
    
    $this->cookieFile       = $this->cookieFileJar;
    $this->outputFile       = "addressBook." . md5($this->login) . ".txt";
    $this->fileHandler      = fopen($this->outputFile, "w");
    
    if ($this->setCurlOption())
    {
      $this->execCurl();
      fwrite($this->fileHandler, $this->outputContent);      
      unset($this->outputContent);
      $this->closeCurl();
      fclose($this->fileHandler);    
      
      $fileContent          = file_get_contents($this->outputFile);
      $searchStr            = "/\.crumb.*\"/";

      preg_match($searchStr, $fileContent, $matches);

      if (!empty($matches))
      {
        $foundStr           = $matches[0];
        
        $pattern            = array (
                                    '/id/', '/(\.?)crumb(\d?)/', '/value/', '/=/', '/\"/'
                                    );
        
        $replacement        = array (
                                    '', '', '', '', ''
                                    );
                                    
        $this->crumb        = preg_replace($pattern, $replacement, $foundStr);
      }
    
      $this->unlinkFile($this->outputFile);
    }
  }

  /**
  * Processes Yahoo! Messenger Friend List (Grouped)
  * @return array|false
  */  
  function processMessengerList()
  {
    $this->initCurl();
    $this->url              = $this->serviceUrl;
    $this->numPostField     = 1;
    
	//updated by ovidiuw3b
	$this->postFields		= "VPC=print&field[allc]=1&field[catid]=0&field[style]=>detailed&submit[action_display]=Display for Printing";
	//end update
	
    $this->cookieFile       = $this->cookieFileJar;
    $this->outputFile       = "addressBook." . md5($this->login) . ".txt";
    $this->fileHandler      = fopen($this->outputFile, "w");
    
    if ($this->setCurlOption())
    {
      $this->execCurl();
	  $res=$this->outputContent;
      $this->closeCurl();
	  
	  $emailA=array();$bulk=array();$contacts=array();
		
		$res=str_replace(array('  ','	',PHP_EOL,"\n","\r\n"),array('','','','',''),$res);
		preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<div\>\<\/div\>(.+)\<\/div\>#U",$res,$bulk);
		if (!empty($bulk))
			{
			foreach($bulk[1] as $key=>$bulkName)
				{
				$nameFormated=trim(strip_tags($bulkName));
				if (preg_match('/\&nbsp\;\-\&nbsp\;/',$nameFormated)) 
					{
					$emailA=explode('&nbsp;-&nbsp;',$nameFormated);
					if (!empty($emailA[1])) $contacts[$emailA[1].'@yahoo.com']=array('first_name'=>$emailA[0],'messenger_id'=>$emailA[1]);
					}
				elseif (!empty($bulk[3][$key])) { $email=strip_tags(trim($bulk[3][$key])); $contacts[$email]=array('first_name'=>$nameFormated,'messenger_id'=>$email); }
				}
			}			
		foreach ($contacts as $email=>$name) if (!$this->isEmail($email)) unset($contacts[$email]);

		return $contacts;
    }    
  }  

  /**
  * Processes Yahoo! Mail for Number of New Messages
  * @return array|false
  */  
  function processNewMail()
  {
    $this->initCurl();
    $this->url              = $this->serviceUrl;
    $this->cookieFile       = $this->cookieFileJar;
    $this->outputFile       = "newMailList." . md5($this->login) . ".txt";
    $this->fileHandler      = fopen($this->outputFile, "w");
    
    if ($this->setCurlOption())
    {
      $this->execCurl();
      fwrite($this->fileHandler, $this->outputContent); 
      unset($this->outputContent);
      $this->closeCurl();
      fclose($this->fileHandler);
      
      $fileContent  = file_get_contents($this->outputFile);
      $fileContent  = strip_tags($fileContent);
      
      // Finds out the string You have N unread Message
      $pattern      = "/inbox\s\(\d+\)/i";
      preg_match($pattern, $fileContent, $match);
      
      // Extracts the number of new message(s)
      $numPattern   = "/\d+/";
      preg_match($numPattern, $match[0], $match);
      
      $list['new_mail']   = $match[0];
      
      $this->unlinkFile($this->outputFile);
      
      if ($match[0] > 0)
      {
        $this->setNewMailStatus(true);
      }
      
      return $list;
    }
  }

  /**
  * Processes Yahoo! Calendar
  * @return array|false
  */
  function processCalendar()
  {
    $this->initCurl();
    $this->url              = $this->serviceUrl;
    $this->url             .= "YYY,dbadeb/srt,0/Yahoo.csv?v=12&Yahoo.csv";
    $this->cookieFile       = $this->cookieFileJar;
    $this->outputFile       = "calendar." . md5($this->login) . ".txt";
    $this->fileHandler      = fopen($this->outputFile, "w");
    
    if ($this->setCurlOption())
    {
      $this->execCurl();
      fwrite($this->fileHandler, $this->outputContent);      
      unset($this->outputContent);
      $this->closeCurl();
      fclose($this->fileHandler);
      
      // Sets the service output as a string
      $fileContent          = file_get_contents($this->outputFile);
      
      // Sets patterns and respective replacement strings to convert the output to a proper CSV format
      $pattern              = array (
                                    "/;\"\"\"/",
                                    "/;\"\"/",
                                    "/\"\"/",
                                    "/;\":\"/",
                                    "/;/"
                                    );
      $replacement          = array (
                                    ";\"\"|\"",
                                    ";\":\"",
                                    "\"|\"",
                                    ";\"\"",
                                    ","
                                    );
                                    
      $fileContent          = preg_replace($pattern, $replacement, $fileContent);

      // Sets the formatted output as an array
      $fileContentArr       = explode("|", $fileContent);

      // Sets the calendar column headings
      $clColumnHeadLine     = trim($fileContentArr[0]);
      $clColumnHeadLine     = str_replace("\"", "", $clColumnHeadLine);
      
      // Sets the calendar column headings into an array
      $clColumnHeadArr      = explode(",", $clColumnHeadLine);
      
      // Unsets the heading line from the file content array
      unset($fileContentArr[0]);
      
      foreach ($fileContentArr as $key => $value)
      {
        // Sets the calendar list individually
        $listColumnLine     = trim($value);
        $listColumnLine     = str_replace("\"", "", $listColumnLine);
        
        // Sets the individual list into an array
        $listColumnArr      = explode(",", $listColumnLine);
        
        // Iterates through each item of individual calendar item in the list
        foreach ($listColumnArr as $listColumnKey => $listColumnValue)
        {
          // Sets the column heading as key
          $listKey          = $clColumnHeadArr[$listColumnKey];
          
          // Sets the value for the key respectively
          $list_[$listKey]  = $listColumnValue;
        }
        
        // Sets the calendar list in an array
        $list[]             = $list_;
      }
      
      $this->unlinkFile($this->outputFile);
      
      return $list;      
    }    
  }
  
  /**
  * Sets the new mail status to true or false
  * @return void
  */  
  function setNewMailStatus($status)
  {
    $this->newMailStatus = ($status) ? true : false;
  }
  
  /**
  * Returns the new mail status
  * @return boolean
  */
  function getNewMailStatus()
  {
    return $this->newMailStatus;
  }
  
  /**
  * Executes cURL Session
  * @return void
  */  
  function execCurl()
  {
    $this->outputContent    = curl_exec($this->curlSession);  
  }

  /**
  * Closes cURL session
  * @return void
  */  
  function closeCurl()
  {
    curl_close($this->curlSession); 
    unset($this->curlSession); 
  }

  /**
  * Unlinks any given file
  * @return void
  */  
  function unlinkFile($fileToUnlink)
  {
    if (file_exists($fileToUnlink))
    {
      unlink($fileToUnlink);
    }
  }

  /**
  * Sets any cURL error generated
  * @return boolean
  */  
  function getCurlError()
  {
    $this->curlError    = curl_error($this->curlSession);
    
    return (!empty($this->curlError)) ? true : false;
  }
  
  /**
  * Sets Error Information
  * @return void
  */  
  function setError($error) 
  {
    $msg  = (!empty($error)) ? $this->getErrorInfo($error) : null;
    $this->errorCount++;
    $this->errorInfo = $msg;
  }

  /**
  * Provides the Error message
  * @param string $error Error code for which error message is generated
  * @return string
  */  
  function getErrorInfo($error) 
  {
    switch ($error) 
    {
      case 'provide_service'    : $msg  = "Must specify a Service"; break;
      
      case 'provide_login'      : $msg  = "Must provide Login name"; break;
                                
      case 'provide_pass'       : $msg  = "Must provide Password"; break;
                                
      case 'provide_ca'         : $msg  = "Must provide a SSL Certificate to verfiy CA cert"; break;
                                
      case 'proxy_required'     : $msg  = "Must provide both Proxy host and port"; break;
                                
      case 'invalid_login'      : $msg  = "Login information incorrect"; break;
                                
      case 'curl_error'         : $msg  = $this->curlError; break;
    }
    
    return $msg;
  }

  /*added by ovidiuw3b*/
  function isEmail($email)
   {
	return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $email);
   }
  /*end code added by ovidiuw3b*/  
  }
?>
 

 

 

其实他们都有api可以使用,参考如下:

 

gmail:

http://www.9lessons.info/2011/06/import-gmail-contacts-google-oauth.html

 

yahoo:

http://developer.yahoo.com/addressbook/

http://developer.yahoo.com/blogs/ydn/posts/2008/09/getting_started/

 

 

 

 

 

 

分享到:
评论

相关推荐

    获取Gmail联系人列表

    在IT行业中,获取Gmail联系人列表是一项常见的需求,尤其对于开发者来说,这可能涉及到集成Gmail服务到自己的应用程序中,比如同步用户通讯录。在这个场景下,利用Google提供的GData API,我们可以轻松地实现这一...

    获取gmail、hotmail、Yahoo mail的联系人邮件地址

    本教程将详细介绍如何利用opencontact.net这个工具获取Gmail、Hotmail和Yahoo Mail的联系人邮件地址,并重点介绍针对Hotmail错误的修正方法。 首先,opencontact.net是一个在线服务,允许用户通过其接口连接到不同...

    Batch库获取MSN好友信息、Gmail邮箱Yahoo邮箱Live邮箱联系人的Demo

    本示例中的"Batch库获取MSN好友信息、Gmail邮箱Yahoo邮箱Live邮箱联系人的Demo"就是一个这样的实例,它展示了如何利用特定的库批量处理获取不同邮件服务提供商的联系人信息。 首先,我们要理解"Batch库"的概念。在...

    asp.net获取gmail联系人

    在ASP.NET中获取Gmail联系人是一个涉及到Web应用程序开发、API交互以及OAuth授权流程的实践过程。这个过程主要分为以下几个步骤: 1. **理解Google API**:首先,我们需要了解Google提供的Gmail API,这是一个允许...

    PHP获取163、sina、sohu、yahoo、126、gmail、tom邮箱联系人地址【已测试2009.10.10】

    最近一直忙于项目上的QQ、MSN、邮箱(目前以实现163、126、gmail、sina、tom、sohu、yahoo等)通讯录地址获取;其中搜狐失效还需研究一下! 在网上找了一些,大部分都已经失效,为此我重新整理了一下;特别放出126的...

    PHP通过SMTP协议获取gmail邮件信息(包括主题、正文、图片、附件等)

    2. 邮件正文,会内嵌收件人与发件人之间最多10封来往邮件; 3. 邮件正文中内嵌的图片,将该图片从远程服务器中下载到本地服务器并替换掉图片的链接到本地服务器中该图片的保存目录(可访问); 4. 将附件从远程...

    PHPmailer用gmail發送郵件

    总结,使用PHPMailer通过Gmail发送邮件涉及到的关键点包括导入PHPMailer库、配置SMTP服务器、设置发件人和收件人的信息、定义邮件内容以及处理发送过程中的错误。通过熟悉这些步骤,你可以轻松地在你的PHP项目中实现...

    php Inivte Email 联系人

    3. **Yahoo**: Yahoo也提供了雅虎联系人API,但是近年来已经逐步退役。目前,获取Yahoo联系人的最佳方式可能是通过Yahoo Mail API,但这也需要用户授权并使用OAuth2进行身份验证。 4. **Sina(新浪)**: 新浪尚未...

    java获取邮件联系人

    这个示例中,我们连接到Gmail的IMAP服务器,打开收件箱,然后遍历所有邮件,从每封邮件的发件人地址中提取姓名和电子邮件。请注意,实际操作可能更复杂,因为联系人可能存储在特定的文件夹或通过其他方式组织。 `...

    PHP CURL GMAIL好友邀请 GMAIL邮箱登录

    标题 "PHP CURL GMAIL好友邀请 GMAIL邮箱登录" 涉及到的主要知识点是使用PHP的CURL库来实现Gmail邮箱的登录以及抓取联系人信息,这在Web开发中是一个常见的应用场景,特别是当你需要集成Gmail服务或者发送邀请邮件时...

    获取yahoo,sina,tom,gmail,163等邮箱通信录

    1. **Yahoo**:Yahoo提供了Yahoo Mail API,基于OAuth2进行身份验证,你可以通过它来获取用户授权,然后访问其联系人数据。 2. **Sina**:新浪邮箱没有公开的官方API供开发者直接获取通信录,但可以通过模拟登录和...

    C#POP3获取邮箱联系人

    首先,我们需要理解的是,大多数现代电子邮件服务如Gmail、Outlook等提供了更高级的API(如IMAP或Exchange Web Services)来处理联系人。IMAP(Internet Message Access Protocol)允许用户查看、搜索和操作邮件存储...

    最新获取邮箱联系人,MSN获取也解决

    在电子邮件服务中,如 Gmail、Yahoo 或 Outlook,用户通常会存储他们的联系人列表,这些联系人信息包括姓名、电子邮件地址和其他联系方式。获取这些联系人的方法通常需要用户授权,通过API接口进行。例如,Google...

    php获取邮箱email好友

    这个任务涉及到与各种邮箱服务提供商的API交互,以便获取用户的联系人列表。在这个场景下,我们关注的是Yahoo、Google(Gmail)、Yeah、163、126、Sina、QQ、Tom和MSN等主流邮箱服务。 首先,我们需要了解每个服务...

    NPOI组件读取Excel与通过Gmail联系人的导入Demo

    获取到授权令牌后,可以使用以下代码来获取Gmail联系人: ```csharp using Google.Apis.Auth.OAuth2; using Google.Apis.Gmail.v1; using Google.Apis.Gmail.v1.Data; // 设置Google服务凭据 UserCredential ...

    PHP通过SMTP协议获取gmail邮件信息(包括主题、正文、图片、附件等) 后端.zip

    4. **遍历邮件**:对于每个邮件ID,使用`imap_fetch_overview`获取邮件的基本信息,如发件人、主题、日期等。然后,使用`imap_fetchbody`获取邮件的正文。 ```php foreach ($messages as $msgNo) { $overview = ...

    php实现一个发送邮件类 gmail邮箱

    composer require phpmailer/phpmailer ``` 安装完成后,引入PHPMailer到你的项目中: ```php require 'vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use ...

    教你如何用outlook收发yahoo.cn邮件和gmail邮件

    【如何使用Outlook收发Yahoo.cn和Gmail邮件】 在IT行业中,电子邮件是日常工作中必不可少的通讯工具。Microsoft Outlook作为一款强大的电子邮件客户端,允许用户管理多个邮件账户,包括Yahoo.cn和Gmail。以下将详细...

    获取邮箱联系人.net代码

    要获取Gmail联系人,首先需要在Google开发者控制台创建项目并启用Gmail API,然后获取OAuth 2.0客户端ID和秘密。接着,使用这些凭据进行身份验证,并请求访问用户联系人的权限。一旦获得授权,就可以调用`Service....

    php导入msn和一些常用邮箱的通讯录

    标题 "php导入msn和一些常用邮箱的通讯录" 涉及到的是使用PHP编程语言来实现从多个流行的电子邮件服务提供商(如Gmail、Yahoo、Sohu、Sina、Tom等)以及MSN(微软的即时通讯服务)导入联系人的功能。这个项目的核心...

Global site tag (gtag.js) - Google Analytics