• 2012 07 17 gmail 抓取联系人 成功


    <?php
    /**
    * 获得Gmail邮箱通讯录列表 -- mail_gmail.class.php
    */
    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;
    }
    
    }
    
    ?>
  • 相关阅读:
    【面试题总结】第三篇
    Django 多账号登录
    Zabbix3.2 监控搭建
    2017.09.24校内训练
    2017.09.06校内训练
    tyvj P1001 第K极值
    洛谷P1020导弹拦截
    洛谷P1006传纸条
    2017.09.10校内训练
    hdu_1086 You can Solve a Geometry Problem too
  • 原文地址:https://www.cnblogs.com/lingmou/p/2689098.html
Copyright © 2020-2023  润新知