【问题标题】:Ionic framework vs Google calendar api离子框架与谷歌日历 api
【发布时间】:2015-12-17 08:51:48
【问题描述】:

我正在使用 Ionic 框架为组织创建一个应用程序,例如会议室预订。我是 Ionic 框架的新手。 我需要你们帮助解决以下问题 1).Oauth for Google 登录 2)通过使用访问令牌发送请求访问谷歌日历 3)需要获取请求的 JSON 响应。 4)另外,重要的是需要获取资源日历(房间,投影仪等)

请指导我如何使用 Ionic 框架做到这一点。到现在我还没有得到任何好的教程。

提前致谢!!!!

【问题讨论】:

  • 我有商业谷歌应用帐户。我需要一个很好的谷歌登录和谷歌日历教程(列出事件、添加事件、列出日历和列出资源日历)。我决定使用 ionic 框架.请帮帮我..
  • 请给我一些很好的教程链接

标签: ionic-framework google-calendar-api


【解决方案1】:

@arun,我使用 ionic2 开发了一个小型混合应用程序,并在应用程序中集成了谷歌日历。您可以查看应用程序@Google calendar in Ionic 2 app demo on android device 的快速演示。 如果这是您正在寻找的内容,我相信您在问题中提到的内容是 google oauth login、访问日历和发送邀请。我不确定您是否正在使用 Ionic2 进行开发。如果是,请查看演示视频和详细步骤。 Demo and steps to integrate google calendar in the Ionic 2 app

【讨论】:

    【解决方案2】:

    Ionic 框架 是 AngularJS 的集成,是跨平台的最佳框架。对 ngCordova 插件的大量支持。

    我有一些链接给你

    1. 对于 Google oAuth - http://blog.ionic.io/oauth-ionic-ngcordova/
    2. 对于谷歌日历 - http://www.raymondcamden.com/2015/09/18/integrating-the-calendar-into-your-ionic-app

    您可以参考 Intel@XDK 是最好的工具之一。我用它来开发交叉开发应用程序,它支持使用 IONIC 的多个框架。

    【讨论】:

      【解决方案3】:

      我一直在寻找将谷歌日历中的数据集成到 Ionic 中的时间,但没有任何运气。

      我现在已经能够通过我在 node.js 中的后端将它集成到我的 ionic 应用程序中,我建议你也这样做。

      这是我在后端使用的代码

      let eventCategories = require('./event.model');
      
      let fs = require('fs');
      let readline = require('readline');
      let google = require('googleapis');
      let googleAuth = require('google-auth-library');
      
      // If modifying these scopes, delete your previously saved credentials
      // at ~/.credentials/calendar-nodejs-quickstart.json
      let SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'];
      let TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
          process.env.USERPROFILE) + '/.credentials/';
      let TOKEN_PATH = TOKEN_DIR + 'calendar-nodejs-quickstart.json';
      
      
      module.exports = {
        getEventCategories,  
        getEvents,
        setResponseStatus
      };
      
      function getEventCategories(){
        return eventCategories.find({});
      }
      
      function getEvents(calendarId) {
        return loadClientSecrets()
          .then(res => authorize(JSON.parse(res))
                          .then(response => listEvents(response, calendarId)))
      
      }
      
      function loadClientSecrets(){
        return new Promise(function (fulfill, reject){
          fs.readFile('client_secret.json', function processClientSecrets(err, content){
            if (err){
              console.log('Error loading client secret file: '+ err);
              reject(err);
            }
            else fulfill(content);
          }) 
        })
      }
      
      
      
      /**
       * Create an OAuth2 client with the given credentials, and then execute the
       * given callback function.
       */
      function authorize(credentials) {
        return new Promise(function (fulfill, reject){
          let clientSecret = credentials.installed.client_secret;
          let clientId = credentials.installed.client_id;
          let redirectUrl = credentials.installed.redirect_uris[0];
          let auth = new googleAuth();
          let oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
      
          // Check if we have previously stored a token.
          fs.readFile(TOKEN_PATH, function(err, token) {
            if (err) {
              fulfill(getNewToken(oauth2Client));
            } else {
              oauth2Client.credentials = JSON.parse(token);
              fulfill(oauth2Client);
            }
          });
        })
      }
      
      /**
       * Get and store new token after prompting for user authorization, and then
       * execute the given callback with the authorized OAuth2 client.
       */
      function getNewToken(oauth2Client) {
        new Promise (function (fulfill, reject){
          let authUrl = oauth2Client.generateAuthUrl({
            access_type: 'offline',
            scope: SCOPES
          });
          console.log('Authorize this app by visiting this url: ', authUrl);
          let rl = readline.createInterface({
            input: process.stdin,
            output: process.stdout
          });
          rl.question('Enter the code from that page here: ', function(code) {
            rl.close();
            oauth2Client.getToken(code, function(err, token) {
              if (err) {
                console.log('Error while trying to retrieve access token', err);
                reject(err);
              }
              oauth2Client.credentials = token;
              storeToken(token);
              fulfill(oauth2Client);
            });
          });
        })
      }
      
      /**
       * Store token to disk be used in later program executions.
       */
      function storeToken(token) {
        try {
          fs.mkdirSync(TOKEN_DIR);
        } catch (err) {
          if (err.code != 'EEXIST') {
            throw err;
          }
        }
        fs.writeFile(TOKEN_PATH, JSON.stringify(token));
        console.log('Token stored to ' + TOKEN_PATH);
      }
      
      /**
       * Lists the next 10 events on the user's primary calendar.
       */
      function listEvents(auth, calendarId) {
        return new Promise(function ( fulfill, reject){
          var calendar = google.calendar('v3');
          calendar.events.list({
            auth: auth,
            calendarId: calendarId,
            timeMin: (new Date()).toISOString(),
            maxResults: 10,
            singleEvents: true,
            orderBy: 'startTime'
          }, function(err, response) {
            if (err) {
              console.log('The API returned an error: ' + err);
              reject(err);
            }
            var events = response.items;
            if (events.length == 0) {
              console.log('No upcoming events found.');
            } else {
              console.log('Upcoming 10 events:');
              for (var i = 0; i < events.length; i++) {
                var event = events[i];
                var start = event.start.dateTime || event.start.date;
                console.log('%s - %s', start, event.summary);
              }
              // return events
              fulfill(events)
            }
          });
        })
      
        function setResponseStatus(){
      
        }
      }
      

      【讨论】:

      • 对不起,我没有使用 node.js 的经验。您如何使用此代码获取应用中的数据?
      • 这只是我的事件控制器的完整副本,我可以通过调用 api 来访问这些方法(我不再从事这个项目)。不知道你到底在问什么,我还是新手,所以我不确定我是否可以进一步帮助你
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 2016-01-03
      • 2017-08-30
      • 1970-01-01
      相关资源
      最近更新 更多