簡體   English   中英

使用OAuth 2.0使用php api對Google日歷進行動態身份驗證

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM