登陆google
public function googleLogin($email,$password){
$session = UserOper::openSession();//如果已经登陆,直接返回
if($session['googleAuth']){
$session->close();
return true;
}
$data = array(
'accountType' => 'GOOGLE',
'Email' => $email,
'Passwd' => $password,
'service' => 'cp', //google 一系列api 的简写,在google 上能找到,可以换成你想要的服务简写
'source' => 'test-oauth-1.0', //给你自己的应用程序命名
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
preg_match('/Auth=.+/',$output,$tempArray);
if($info['http_code']!=200 or empty($tempArray)){
return false;
}
$auth = 'Authorization: GoogleLogin auth='.substr($tempArray[0],5);
$session['googleAuth'] = $auth;
return true;
}
获取联系人信息(atom格式数据源)
public function getGoogleResource($url){
$session = UserOper::openSession();
if(!$session['googleAuth']){
$session->close();
return false;
}
$session->close();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER,array($session['googleAuth']));
$output = curl_exec($ch);
$info = curl_getinfo($ch);
if($info['http_code']!=200) return false;
return $output;
}
解析数据源,读取联系人email地址(使用 php DOMDocument)
public function getGoogleFriends(){
$url = 'http://www.google.com/m8/feeds/contacts/default/full';
$source = $this->getGoogleResource($url);
$friends = array();
if($source){
$dom = new DOMDocument();
$dom->loadXML($source);
$entries = $dom->getElementsByTagName('entry');
foreach ( $entries as $entry ){
$email = $entry->getElementsByTagName('email');
$value = $email->item(0)->getAttributeNode("address")->value;
$friends[$value] = $value;
}
return $friends;
}
return false;
}
分享到:
相关推荐
在C++下,Curl获取网络时间的源代码,适合新手小白使用。
命令行下调用curl获取网页信息,例如在Java servlet中使用response.getWriter().print("success") curl就可以获取到"success",并保存到check.txt中,再从check.txt中读取数据,并做判断
利用openssl和curl库获取https证书
curl官网下载源码,mingw32-make.exe 编译,qt新建工程引入动态库,使用curl进行网络请求。
【Azure Developer】使用 CURL 获取 Key Vault 中 Secrets 中的值.doc
使用curl操作openstack swift使用curl操作openstack swift使用curl操作openstack swift使用curl操作openstack swift使用curl操作openstack swift使用curl操作openstack swift使用curl操作openstack swift使用curl...
qt5使用curl实现文件下载的示例程序,详细操作请参考博客http://blog.csdn.net/xueyushenzhou/article/details/51702672#t3
想要获取状态码,需要在执行curl_exec后再通过curl_getinfo来获取。例如: 复制代码 代码如下: $ch = curl_init (); curl_setopt($ch, CURLOPT_URL, ‘http://www.google.com.hk’); curl_setopt($ch, CURLOPT_TIME...
本文实例讲述了php使用curl获取https请求的方法。分享给大家供大家参考。具体分析如下: 今日在做一个项目,需要curl获取第三方的API,对方的API是https方式的。 之前使用curl能获取http请求,但今天获取https请求时...
可以轻松获取对方的head头部seo信息
curl下载curl包下载
简单使用curl进行get请求并将服务器返回存进本地文件,简单使用curl进行get请求并将服务器返回存进本地文件
主要介绍了PHP CURL获取返回值的方法,需要的朋友可以参考下
一个完整的使用CURL抓取网页数据 使用stl string分析网页数据,将提取的数据输出到log.txt中
写了个msnp 包来做,功能也是很强大,想到自己只是获取联系人列表,发现一个牛牛写的一个class很实用。 copy下来直接设参数,报curl_init 找不到,发现自己的php版本不支持curl。 好吧看看代码中是怎么掉的,哈哈...
仅供自己备份使用。 curl c++ 使用实例,项目中使用,没有改动直接贴过来。 curl https访问,curl-7.60.0源码版本
主要介绍了PHP中使用CURL获取页面title例子,本文使用正则实现获取页面title、页面编码、<head>标签中的内容,需要的朋友可以参考下
cURL无法向本地文件系统或类似目的写入数据。 25:FTP 无法STOR文件。服务器拒绝了用于FTP上传的STOR操作。 26:读错误。各类读取问题。 27:内存不足。内存分配请求失败。 28:操作超时。到达指定的超时期限条件。 30:...