简体   繁体   English

使用OAuth 2.0使用php api对Google日历进行动态身份验证

[英]dynamically authenticate to google calender using php api Using OAuth 2.0

we want to fetch data from google calender and insert data through external api source. 我们想从Google日历中获取数据,并通过外部api源插入数据。 but we want method to automatically client login using email and password alredy saved. 但我们希望使用保存的电子邮件和密码自动进行客户端登录的方法。

    $authUrl = $client->createAuthUrl ();
echo $authUrl;
print "<a class='login' href='$authUrl'>Connect Me!</a>";

Client should not click on login only credentials re post through curl and client get logged in google calender and token is generated dynamically. 客户端不应单击仅登录凭据通过curl重新发布,并且客户端必须登录到Google日历中,并且令牌是动态生成的。 we have used google calender php api. 我们已经使用谷歌日历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);

} }

This code doesn't generate token . 此代码不会生成令牌。

We does not require redirecting the user or doing a token exchange. 我们不需要重定向用户或进行令牌交换。 we require if $user = 'user@gmail.com'; 我们需要$ user ='user@gmail.com'; $pass = 'myPassword'; $ pass ='myPassword'; passed to code token get generated for calender api Using OAuth 2.0 使用OAuth 2.0为日历API生成传递给代码令牌的消息

Your url has https so you need to handle it by using this: 您的网址包含https,因此您需要使用以下网址进行处理:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

Use this option to see the debugging messages of curl operation so that you can trace yourself: 使用此选项可查看curl操作的调试消息,以便您可以跟踪自己:

curl_setopt($curl, CURLOPT_VERBOSE, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM