How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • const {google} = require('googleapis');
    const fcm = google.fcm('v1');
    Docs
  • const {GoogleAuth} = require('google-auth-library');
    
    /**
    * Instead of specifying the type of client you'd like to use (JWT, OAuth2, etc)
    * this library will automatically choose the right client based on the environment.
    */
    async function main() {
      const auth = new GoogleAuth({
        scopes: 'https://www.googleapis.com/auth/cloud-platform'
      });
      const client = await auth.getClient();
      const projectId = await auth.getProjectId();
      const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;
      const res = await client.request({ url });
      console.log(res.data);
    }
    
    main().catch(console.error);
    Docs
  • // Before running the sample:
    // - Enable the API at:
    //   https://console.developers.google.com/apis/api/fcm.googleapis.com
    // - Login into gcloud by running:
    //   `$ gcloud auth application-default login`
    // - Install the npm module by running:
    //   `$ npm install googleapis`
    
    const {google} = require('googleapis');
    const fcm = google.fcm('v1');
    
    async function main() {
      const auth = new google.auth.GoogleAuth({
        // Scopes can be specified either as an array or as a single, space-delimited string.
        scopes: [
          'https://www.googleapis.com/auth/cloud-platform',
          'https://www.googleapis.com/auth/firebase.messaging',
        ],
      });
    
      // Acquire an auth client, and bind it to all future calls
      const authClient = await auth.getClient();
      google.options({auth: authClient});
    
      // Do the magic
      const res = await fcm.projects.messages.send({
        // Required. It contains the Firebase project id (i.e. the unique identifier for your Firebase project), in the format of `projects/{project_id\}`. For legacy support, the numeric project number with no padding is also supported in the format of `projects/{project_number\}`.
        parent: 'projects/my-project',
    
        // Request body metadata
        requestBody: {
          // request body parameters
          // {
          //   "message": {},
          //   "validateOnly": false
          // }
        },
      });
      console.log(res.data);
    
      // Example response
      // {
      //   "android": {},
      //   "apns": {},
      //   "condition": "my_condition",
      //   "data": {},
      //   "fcmOptions": {},
      //   "name": "my_name",
      //   "notification": {},
      //   "token": "my_token",
      //   "topic": "my_topic",
      //   "webpush": {}
      // }
    }
    
    main().catch(e => {
      console.error(e);
      throw e;
    });
    
    Docs
  • const {ExternalAccountClient} = require('google-auth-library');
    const jsonConfig = require('/path/to/config.json');
    
    async function main() {
      const client = ExternalAccountClient.fromJSON(jsonConfig);
      client.scopes = ['https://www.googleapis.com/auth/cloud-platform'];
      // List all buckets in a project.
      const url = `https://storage.googleapis.com/storage/v1/b?project=${projectId}`;
      const res = await client.request({url});
      console.log(res.data);
    }
    Docs
  • const {JWT} = require('google-auth-library');
    const keys = require('./jwt.keys.json');
    
    async function main() {
      const client = new JWT({
        email: keys.client_email,
        key: keys.private_key,
        scopes: ['https://www.googleapis.com/auth/cloud-platform'],
      });
      const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`;
      const res = await client.request({url});
      console.log(res.data);
    }
    
    main().catch(console.error);
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples