【问题标题】:dynamically authenticate to google calender using php api Using OAuth 2.0使用 php api 使用 OAuth 2.0 动态验证谷歌日历
【发布时间】:2014-01-20 13:04:13
【问题描述】:

我们想从谷歌日历中获取数据并通过外部 api 源插入数据。 但我们希望使用已保存的电子邮件和密码自动登录客户端。

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

客户端不应单击仅登录凭据通过 curl 和客户端获取重新发布 登录谷歌日历和令牌是动态生成的。 我们使用了googlecalender 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 = '我的密码'; 使用 OAuth 2.0 为日历 api 生成传递给代码令牌

【问题讨论】:

    标签: php curl google-api google-api-php-client


    【解决方案1】:

    你的 url 有 https 所以你需要用这个来处理它:

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    

    使用此选项可以查看 curl 操作的调试信息,以便您自己跟踪:

    curl_setopt($curl, CURLOPT_VERBOSE, true);
    

    【讨论】:

    • 您能否发布代码以从 google 帐户为 google 日历动态生成令牌
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 2015-01-10
    相关资源
    最近更新 更多