• php curl 获取 邮箱通讯录 gmail


    2012-3-24 经测试可正常使用

    <?php
    
    error_reporting(E_ALL);
    
    $username = "gmail@gmail.com";
    $password = "password";
    
    $gmail = new mail_gmail();
    $result = $gmail->getAddressList($username, $password);
    
    $data = json_decode($result, true);
    $list = array();
    foreach ($data['feed']['entry'] as $entry) {
        $list['username'] = $entry['title']['$t'];
        $list['email']= $entry['gd$email'][0]['address'];
        $lists[] = $list;
    }
    
    var_dump($lists);
    
    
    class mail_gmail {
        function getAddressList($username, $password) {
            $login_url = "https://www.google.com/accounts/ClientLogin";
            $fields = array(
                'Email' => $username,
                '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/$username/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);
            return $result;
        }
    
    }
    
    ?>
    
  • 相关阅读:
    80.共享内存实现进程通信
    79.cgi硬盘查询个人信息
    78.pipe多管道云端,客户端通信
    77.邮槽通信
    76.CGI编码
    strnpy函数
    POJ 1258 Agri-Net(Prim算法)
    0X7FFFFFFF,0X80000000
    Visual C++中min()和max()函数的使用
    POJ 2421 Constructing Roads(Kruskal算法)
  • 原文地址:https://www.cnblogs.com/ybbqg/p/2415714.html
Copyright © 2020-2023  润新知