[英]dynamically authenticate to google calender using php api Using OAuth 2.0
我们想从Google日历中获取数据,并通过外部api源插入数据。 但我们希望使用保存的电子邮件和密码自动进行客户端登录的方法。
$authUrl = $client->createAuthUrl ();
echo $authUrl;
print "<a class='login' href='$authUrl'>Connect Me!</a>";
客户端不应单击仅登录凭据通过curl重新发布,并且客户端必须登录到Google日历中,并且令牌是动态生成的。 我们已经使用谷歌日历php API。
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"client_id" => '',
"client_secret" => '');
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt ($curl, CURLOPT_HTTPHEADER, Array("application/x-www-form-urlencoded"));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if($client->isAccessTokenExpired()) {
echo 'Access Token Expired'; // debug
$json_response = curl_exec($curl); // JSON value returned
curl_close($curl);
$authObj = json_decode($json_response);
}
此代码不会生成令牌。
我们不需要重定向用户或进行令牌交换。 我们需要$ user ='user@gmail.com'; $ pass ='myPassword'; 使用OAuth 2.0为日历API生成传递给代码令牌的消息
您的网址包含https,因此您需要使用以下网址进行处理:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
使用此选项可查看curl操作的调试消息,以便您可以跟踪自己:
curl_setopt($curl, CURLOPT_VERBOSE, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.