Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

connect nextjs to google sheets

import { google } from 'googleapis';
export async function getEmojiList() {
  try {
    const target = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
    const jwt = new google.auth.JWT(
      process.env.GOOGLE_SHEETS_CLIENT_EMAIL,
      null,
      (process.env.GOOGLE_SHEETS_PRIVATE_KEY || '').replace(/
/g, '
'),
      target
    );

    const sheets = google.sheets({ version: 'v4', auth: jwt });
    const response = await sheets.spreadsheets.values.get({
      spreadsheetId: process.env.SPREADSHEET_ID,
      range: 'emoji', // sheet name
    });

    const rows = response.data.values;
    if (rows.length) {
      return rows.map((row) => ({
        title: row[2],
        subtitle: row[3],
        code: row[4],
        browser: row[5],
        short_name: row[17],
        emojipedia_slug: row[18],
        descriptions: row[19],
      }));
    }
  } catch (err) {
    console.log(err);
  }
  return [];
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Backbone Model Most Simple 
Javascript :: react : calling APIs after render w error message 
Javascript :: verify if user input is equal to javascript 
Javascript :: top of stack javascript 
Javascript :: Javascript set control state none opposite 
Javascript :: Backbone Get Model From Collection 
Javascript :: javascript nodejs array to listnode 
Javascript :: clear an array 
Javascript :: add even javascript 
Javascript :: Solution-4-C--solution options for reverse bits algorithm js 
Javascript :: add seconds to date 
Javascript :: get selected data items kendo grid 
Javascript :: how to check the validation of time in react datetime 
Javascript :: regexp object 
Javascript :: for loop javascript array of objects 
Javascript :: moment max 
Javascript :: javascript last element 
Javascript :: singleton class in js 
Javascript :: sweetalert2 redirect after ok 
Javascript :: knexjs char 
Javascript :: port y build - vite.config.js 
Javascript :: loop,array javascript 
Javascript :: JavaScript Changing Prototype 
Javascript :: javascript Skip Items 
Javascript :: JavaScript Comparison and Logical Operators 
Javascript :: card types regex 
Javascript :: remoteevent dont send object 
Javascript :: change y scale phaser 
Javascript :: phaser create animation from sprite config.js 
Javascript :: javascript accordion 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =