dongmu1951 2014-10-27 15:42
浏览 49
已采纳

创建Google登录页面以访问服务

I need to build a small web application which connects to Google Calendars and fetches a specified event set. I've read the documentation, and I understand that I need to authenticate the user to my app which I created on the Google Developer console.

I'm trying to implement an authentication with a popup window (I'm using fancybox for this). This is the <div> in which the login data goes: <div id="login-popup" style="display:none"></div>

This is the JS code I'm using to call the auth.php file:

    $.get("/auth.php", function(result) {
            $('#login-popup').append(result);
            $.fancybox({
                href: "#login-popup",
                autoSize: true,
                width: "60%",
                fitToView: true
            });
        });

And finally this is the PHP code that sends the GET request to Google's API:

$ch = curl_init();
if($ch) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $query);
    $result = curl_exec($ch);

    curl_close($ch);
}
else {
    throw new RuntimeException("Hiba történt a távoli adatok elérése közben!");
}
echo json_encode($result);

So this popup comes up after this, as it's supposed to be:

enter image description here

After I enter my credentials however, it redirrects me to Google's login website (https://accounts.google.com/ServiceLoginAuth).

My problem:

I need to be able to get data back from this popup window to get the access token I can later use on my Calendar API call. What do I need do to achieve this?

  • 写回答

1条回答 默认 最新

  • doxd96148 2014-10-27 15:57
    关注

    The reason you are being redirected is because you are essentially loading google's page into an iframe. Everything that is normally called on their login page on submit is called when you input. So basically you're just opening a window to google within your website.

    The correct way to implement this would be to use google's oauth API. (https://developers.google.com/accounts/docs/OAuth2 or more specifically, https://developers.google.com/accounts/docs/OAuth2Login)

    You'll need to register a project and get a developer/API key.

    The google docs are very comprehensive, so you should be able to follow them pretty easily!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题