相关疑难解决方法(0)

使用Firebase Auth访问Google Calendar API

我正在使用AngularJS,Firebase(SDK v3)和Google Calendar API构建Web应用程序.我正在使用Google OAuth对用户进行身份验证.我的目的是能够从Firebase中的数据库节点创建日历事件.到目前为止,我已设法请求访问日历范围:

_authProvider = new firebase.auth.GoogleAuthProvider();
// Get permission to manage Calendar
_authProvider.addScope("https://www.googleapis.com/auth/calendar");
_fbAuthObject.signInWithRedirect(_authProvider);
Run Code Online (Sandbox Code Playgroud)

我正在使用重定向流进行身份验证,因此身份验证重定向可用:

_fbAuthObject.getRedirectResult()
    .then(function _readToken(result) {
      if (result.credential) {
        _googleToken = result.credential.accessToken;
        var authHeader = 'Bearer '+ _googleToken;

        // Just a test call to the api, returns 200 OK 
        $http({
          method: 'GET',
          headers: {
            'Authorization': authHeader
          },
          url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList/primary'
        })
          .then(function success(response) {
            console.log('Cal response', response);
          },
          function error(response) {
            console.log('Error', response);
          });
Run Code Online (Sandbox Code Playgroud)

但是,在初始登录之外,似乎无法通过Firebase SDK获取Google访问令牌.似乎只能访问Firebase JWT令牌,而不能使用Calendar API.我可以存储访问令牌,但这不能解决刷新令牌等问题.有没有办法通过Firebase SDK获取当前的Google Access令牌,如果没有,那么有什么其他解决方案可以解决问题两次验证用户?

更新1:

好像其他人一直在努力解决与Facebook身份验证相似的问题.在该问题上,有一个指向Firebase文档 …

authentication google-calendar-api angularjs firebase firebase-authentication

9
推荐指数
1
解决办法
4158
查看次数

使用服务帐户插入Google日历条目

我正在尝试使用服务帐户在Google日历上创建条目.我真的很接近这一点,但最后一行不起作用.500 Internal Service Error当我让这个运行时,我得到了一个.否则,程序运行无错误,无论价值多少.

Calendar.php文件的内容可以发现在这里.在insert()我试图调用方法开始在该文件上的1455线.

<?php

function calendarize ($title, $desc, $ev_date, $cal_id) {

    session_start();

    /************************************************
    Make an API request authenticated with a service
    account.
    ************************************************/
    set_include_path( '../google-api-php-client/src/');

    require_once 'Google/Client.php';
    require_once 'Google/Service/Calendar.php';

    // (not real keys)
    $client_id = '843319906820-jarm3f5ctbtjj9b7lp5qdcqal54p1he6.apps.googleusercontent.com';
    $service_account_name = '843319906820-jarm3f5ctbtjj7b7lp5qdcqal54p1he6@developer.gserviceaccount.com';
    $key_file_location = '../google-api-php-client/calendar-249226a7a27a.p12';

//    echo pageHeader("Service Account Access");
    if (!strlen($service_account_name) || !strlen($key_file_location))
        echo missingServiceAccountDetailsWarning();

    $client = new Google_Client();
    $client->setApplicationName("xxxx Add Google Calendar Entries");

    if (isset($_SESSION['service_token'])) {
        $client->setAccessToken($_SESSION['service_token']);
    }

    $key = file_get_contents($key_file_location); …
Run Code Online (Sandbox Code Playgroud)

php google-calendar-api google-api-php-client

8
推荐指数
2
解决办法
1万
查看次数