2017-02-07 6 views
3

GoogleのカレンダーAPIを使用して特定のカレンダーの情報を取得しようとしています。このエラーが発生し続けるCannot read property 'signIn' of null。私はここの例をオンラインで使用していますhttps://developers.google.com/google-apps/calendar/quickstart/jsGoogleカレンダーAPIが「プロパティを読み取れません」signIn 'of null'

これはなぜ起こっているのですか?誰かがカレンダーデータを取得するためのより簡単な方法を教えてくれますか?基本的には、カレンダーフィードのどの部屋が予約可能かを知りたいです。カレンダーAPIを使用してこれを行うことはできますか?

const CLIENT_ID = '418414126140-u5u3r2ampke8egh7d2tk50ferkl8ri26.apps.googleusercontent.com'; 
const SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]; 

app.factory('getCalendar', ['$q', function($q){ 
    return function checkAuth() { 
     var deferred = $q.defer(); 

     function handleClientLoad() { 
      gapi.load('client:auth2', initClient); 
     } 
     handleClientLoad(); 

     function initClient() { 
      gapi.client.init({ 
       "client_id": CLIENT_ID, 
       "scope": SCOPES 
      }).then(function() { 
       gapi.auth2.getAuthInstance().signIn(); 
      }); 
     } 

     function updateSigninStatus(isSignedIn) { 
      if (isSignedIn) { 
       console.log("You are authorized"); 
       listUpcomingEvents(); 
      } else { 
       console.log("You are not authorized"); 
      } 
     } 

     function listUpcomingEvents() { 
      gapi.client.calendar.events.list({ 
       'calendarId': 'primary', 
       'timeMin': (new Date()).toISOString(), 
       'showDeleted': false, 
       'singleEvents': true, 
       'maxResults': 10, 
       'orderBy': 'startTime' 
      }).then(function(response) { 
       console.log(response); 
       deferred.resolve(response); 

      }); 
     } 
     return deferred.promise; 

    } //return ends here 

}]); 

答えて

-1

gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);代わりのgapi.auth2.getAuthInstance().signIn();を使用してみてください。このサンプルcodeでは、Google JavaScriptクライアントAPIライブラリを使用してAPIを認証したり、APIとのやりとりを行う方法についてご説明しています。

また、related SO threadにチェックし、役立つかどうかを確認してください。

UPDATE:

入手可能であるか、またはないあなたのカレンダー上のどの部屋をチェックする方法上の任意のアイデア?

あなたは、このリンクをチェックすることがあります。Google Calendar Api, Is meeting Room available?

あなたは部屋への読み取りアクセス権を持つユーザーとして認証する必要があります。次に、CalendarリソースAPIのresourceEmailフィールドを取得し、events.list() Calendar API呼び出しでcalendarIdとして使用できます。

+0

ありがとうございました。私はこのチュートリアルをオンラインで見つけました。このチュートリアルは、Googleのドキュメントと比較してはるかに使いやすいものです。 https://www.youtube.com/watch?v=0rZmp3Ew_kA カレンダーのどの部屋をチェックする方法はありますか? –

関連する問題