Actor Oauth Connections spreadsheets avatar
Actor Oauth Connections spreadsheets

Deprecated

Pricing

Pay per usage

Go to Store
Actor Oauth Connections spreadsheets

Actor Oauth Connections spreadsheets

Deprecated

Developed by

Kacka Test

Kacka Test

Maintained by Community

0.0 (0)

Pricing

Pay per usage

0

Total users

1

Monthly users

1

Runs succeeded

0%

Last modified

a month ago

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:20
# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
# Run the image.
CMD npm start --silent

.actor/actor.json

{
"actorSpecification": 1,
"name": "actor-oauth-connections-spreadsheets",
"title": "Scrape single page in JavaScript",
"description": "Scrape data from single page with provided URL.",
"version": "0.0",
"meta": {
"templateId": "js-start"
},
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}

.actor/input_schema.json

{
"title": "Scrape data from a web page",
"type": "object",
"schemaVersion": 1,
"properties": {
"oAuthAccount.Vf5VBFhcxfqcYK0pp": {
"title": "Google Account Id",
"description": "Google Account Id",
"type": "string",
"editor": "textfield"
},
"sheetId.Vf5VBFhcxfqcYK0pp": {
"title": "sheet id test",
"description": "test",
"type": "string",
"editor": "textfield"
}
},
"required": []
}

src/main.js

1import { Actor } from 'apify';
2import { OAuth2Client } from 'google-auth-library';
3import { sheets } from '@googleapis/sheets';
4
5await Actor.init();
6
7const input = await Actor.getInput();
8const { spreadsheetId } = input;
9
10const getSpreadsheetClientV2 = async (input) => {
11 // the Vf5VBFhcxfqcYK0pp is autogenerated id after saving google app clientId and clientSecret to Actor settings Oauth app
12 const accountId = input['oAuthAccount.Vf5VBFhcxfqcYK0pp'];
13 console.log(`accountId: ${accountId}`);
14
15 const headers = { Authorization: `Bearer ${process.env.APIFY_TOKEN}` };
16 const response = await fetch(`${process.env.APIFY_API_BASE_URL}v2/actor-oauth-accounts/${accountId}`, { headers })
17 const credentialsFromApi = await response.json();
18
19 const client = new OAuth2Client({
20 // from google console app, put in process env
21 clientId: process.env.CLIENT_ID,
22 clientSecret: process.env.CLIENT_SECRET,
23 credentials: credentialsFromApi.data.data,
24 });
25
26 console.log(`client: ${JSON.stringify(client)}`);
27
28 return {
29 client,
30 spreadsheetClient: sheets({ version: 'v4', auth: client })
31 }
32}
33
34const testSpeadsheetClient = async (spreadsheetClient) => {
35 const spreadsheetMetadata = await spreadsheetClient.spreadsheets.get({ spreadsheetId });
36 const sheetsMetadata = spreadsheetMetadata.data.sheets.map((sheet) => sheet.properties);
37 const { title: firstSheetName, sheetId: firstSheetId } = sheetsMetadata[0];
38 console.log(`name of the first sheet: ${firstSheetName}`);
39 console.log(`id of the first sheet: ${firstSheetId}`);
40}
41
42const { spreadsheetClient, client } = await getSpreadsheetClientV2(input);
43await testSpeadsheetClient(spreadsheetClient);
44
45const { token } = await client.getAccessToken();
46
47const response = await fetch('https://www.googleapis.com/oauth2/v3/userinfo', {
48 headers: { Authorization: `Bearer ${token}`},
49})
50
51console.log('Userinfo profile response');
52console.log(await response.json());
53
54await Actor.exit();

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.gitignore

# This file tells Git which files shouldn't be added to source control
.DS_Store
.idea
dist
node_modules
apify_storage
storage/*
!storage/key_value_stores
storage/key_value_stores/*
!storage/key_value_stores/default
storage/key_value_stores/default/*
!storage/key_value_stores/default/INPUT.json

package.json

{
"name": "js-scrape-single-page",
"version": "0.0.1",
"type": "module",
"description": "This is an example of an Apify actor.",
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"apify": "^3.1.10",
"axios": "^1.5.0",
"cheerio": "^1.0.0-rc.12",
"google-auth-library": "^9.13.0",
"@googleapis/sheets": "^8.0.0"
},
"scripts": {
"start": "node ./src/main.js",
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
},
"author": "It's not you it's me",
"license": "ISC"
}