Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=44";
import { google } from "npm:googleapis";
export async function getAccessToken(accountId: string, bearer = Deno.env.get("pipedream")) {
const response = await fetchJSON(
`https://api.pipedream.com/v1/accounts/${accountId}?include_credentials=1`,
{ bearer },
);
return response.data.credentials.oauth_access_token;
}
export function googleService(service: string, accessToken: string) {
return google[service]({
version: "v3",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
}
export async function pipeDreamGoogle(service: string, accountId: string, bearer = Deno.env.get("pipedream")) {
const accessToken = await getAccessToken(accountId, bearer);
return googleService(service, accessToken);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
May 17, 2024