简体   繁体   中英

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. 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. we have used google calender 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'; $pass = 'myPassword'; passed to code token get generated for calender api Using OAuth 2.0

Your url has https so you need to handle it by using this:

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_setopt($curl, CURLOPT_VERBOSE, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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