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 {auth, Compute} = require('google-auth-library');
    
    async function main() {
      const client = new Compute({
        // Specifying the service account email is optional.
        serviceAccountEmail: 'my-service-account@example.com'
      });
      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);
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">const</span> auth<span class="token operator">:</span> GoogleAuth <span class="token keyword">import</span> auth</code></pre>
    Docs
    0
  • 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);
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">GoogleAuth</span> <span class="token keyword">import</span> GoogleAuth</code></pre>
    Docs
    0
  • 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();
      // 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);
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    Docs
    0
  • // Main process
    const { inAppPurchase } = require('electron')
    const PRODUCT_IDS = ['id1', 'id2']
    
    // Listen for transactions as soon as possible.
    inAppPurchase.on('transactions-updated', (event, transactions) => {
      if (!Array.isArray(transactions)) {
        return
      }
    
      // Check each transaction.
      transactions.forEach(function (transaction) {
        const payment = transaction.payment
    
        switch (transaction.transactionState) {
          case 'purchasing':
            console.log(`Purchasing ${payment.productIdentifier}...`)
            break
    
          case 'purchased': {
            console.log(`${payment.productIdentifier} purchased.`)
    
            // Get the receipt url.
            const receiptURL = inAppPurchase.getReceiptURL()
    
            console.log(`Receipt URL: ${receiptURL}`)
    
            // Submit the receipt file to the server and check if it is valid.
            // @see https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
            // ...
            // If the receipt is valid, the product is purchased
            // ...
    
            // Finish the transaction.
            inAppPurchase.finishTransactionByDate(transaction.transactionDate)
    
            break
          }
    
          case 'failed':
    
            console.log(`Failed to purchase ${payment.productIdentifier}.`)
    
            // Finish the transaction.
            inAppPurchase.finishTransactionByDate(transaction.transactionDate)
    
            break
          case 'restored':
    
            console.log(`The purchase of ${payment.productIdentifier} has been restored.`)
    
            break
          case 'deferred':
    
            console.log(`The purchase of ${payment.productIdentifier} has been deferred.`)
    
            break
          default:
            break
        }
      })
    })
    
    // Check if the user is allowed to make in-app purchase.
    if (!inAppPurchase.canMakePayments()) {
      console.log('The user is not allowed to make in-app purchase.')
    }
    
    // Retrieve and display the product descriptions.
    inAppPurchase.getProducts(PRODUCT_IDS).then(products => {
      // Check the parameters.
      if (!Array.isArray(products) || products.length <= 0) {
        console.log('Unable to retrieve the product informations.')
        return
      }
    
      // Display the name and price of each product.
      products.forEach(product => {
        console.log(`The price of ${product.localizedTitle} is ${product.formattedPrice}.`)
      })
    
      // Ask the user which product he/she wants to purchase.
      const selectedProduct = products[0]
      const selectedQuantity = 1
    
      // Purchase the selected product.
      inAppPurchase.purchaseProduct(selectedProduct.productIdentifier, selectedQuantity).then(isProductValid => {
        if (!isProductValid) {
          console.log('The product is not valid.')
          return
        }
    
        console.log('The payment has been added to the payment queue.')
      })
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">const</span> inAppPurchase<span class="token operator">:</span> Electron<span class="token punctuation">.</span>InAppPurchase <span class="token keyword">import</span> inAppPurchase</code></pre>
    Docs
    0
  • 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);
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">class</span> <span class="token class-name">ExternalAccountClient</span> <span class="token keyword">import</span> ExternalAccountClient</code><div class="typing-tooltip-markup">Dummy class with no constructor. Developers are expected to use fromJSON.</div></pre>
    Docs
    0
  • const {auth} = require('google-auth-library');
    
    // load the environment variable with our keys
    const keysEnvVar = process.env['CREDS'];
    if (!keysEnvVar) {
      throw new Error('The $CREDS environment variable was not found!');
    }
    const keys = JSON.parse(keysEnvVar);
    
    async function main() {
      // load the JWT or UserRefreshClient from the keys
      const client = auth.fromJSON(keys);
      client.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);
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">const</span> auth<span class="token operator">:</span> GoogleAuth <span class="token keyword">import</span> auth</code></pre>
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples