googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.38k stars 1.91k forks source link

Keep api #3320

Open giagiac opened 1 year ago

giagiac commented 1 year ago

this is what i’m trying (see code below), received 200 but no data in the body, if i well understood if i don’t send nothing as a get parameters the default json that i received back show the trash folder of keep notes - that was not empty.

there aren’t any example for nodejs except java and REST - I also tried calendar api with same token logic but it doesn’t work, in this last case i received 400 with localhost:80 error.

My goal is to fetch all keep notes as a list (as described in the documentation).

Thanks

const { google } = require("googleapis");

const axios = require('axios');

start()

async function start () {

const auth = new google.auth.GoogleAuth({ keyFile: "account_key.json", scopes: [ "https://www.googleapis.com/auth/keep" ], // 'online' (default) or 'offline' (gets refresh_token) access_type: 'offline', include_granted_scopes: true });

const url = "https://keep.googleapis.com/v1/notes?pageSize=10"

const token = await auth.getAccessToken()

console.log(token)

axios.request({ url, method: 'GET', headers: { 'Content-Type': 'application/json', 'Accept-Encoding': 'application/json', Authorization: Bearer ${token} }, }) .then(response => { console.log(response.data) }) .catch(err => { console.log('err :', err); }); }