Last active
January 30, 2021 16:55
-
-
Save thesandlord/4740bfaca43d67fe6865c097db2a4016 to your computer and use it in GitHub Desktop.
Revisions
-
thesandlord revised this gist
Jan 5, 2018 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,7 +73,11 @@ firebase.auth().onAuthStateChanged(function(user) { function startApp(user) { console.log(user); // Make sure to refresh the Auth Token in case it expires! firebase.auth().currentUser.getToken() .then(function(){ return gapi.client.calendar.events .list({ calendarId: "primary", timeMin: new Date().toISOString(), @@ -82,7 +86,8 @@ function startApp(user) { maxResults: 10, orderBy: "startTime" }) }) .then(function(response) { console.log(response); }); } -
thesandlord created this gist
Jan 3, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ /** * @license * Copyright 2018, Google, Inc. * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var config = { // REPLACE WITH THE CONFIG OBJECT YOU CREATED // https://medium.com/@SandeepDinesh/using-google-apis-with-firebase-auth-and-firebase-ui-on-the-web-46e6189cf571 }; firebase.initializeApp(config); var uiConfig = { signInSuccessUrl: "localhost:5000", // Assuming you are running on your local machine signInOptions: [ { provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID, scopes: config.scopes } ], // Terms of service url. tosUrl: "<your-tos-url>" }; // Initialize the FirebaseUI Widget using Firebase. var ui = new firebaseui.auth.AuthUI(firebase.auth()); // The start method will wait until the DOM is loaded. ui.start("#firebaseui-auth-container", uiConfig); // This function will trigger when there is a login event firebase.auth().onAuthStateChanged(function(user) { console.log(user) // Make sure there is a valid user object if (user) { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://apis.google.com/js/api.js"; // Once the Google API Client is loaded, you can run your code script.onload = function(e) { // Initialize the Google API Client with the config object gapi.client .init({ apiKey: config.apiKey, clientId: config.clientID, discoveryDocs: config.discoveryDocs, scope: config.scopes.join(" ") }) // Loading is finished, so start the app .then(function() { // Make sure the Google API Client is properly signed in if (gapi.auth2.getAuthInstance().isSignedIn.get()) { startApp(user); } else { firebase.auth().signOut(); // Something went wrong, sign out } }); }; // Add to the document document.getElementsByTagName("head")[0].appendChild(script); } }); function startApp(user) { console.log(user); 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); }); }