-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
priority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is your feature request related to a problem? Please describe.
I am getting below error when I tried to run googleapis on edge runtime.

Describe the solution you'd like
Please use fetch API internally for calling Google APIs instead of https
Describe alternatives you've considered
I used calling API endpoints by providing access_token and called fetch API
import { SignJWT, importPKCS8 } from "jose";
import { env } from "./env.mjs";
const payload = {
iss: env.GOOGLE_SA_CLIENT_EMAIL,
scope: "https://www.googleapis.com/auth/spreadsheets.readonly",
aud: "https://www.googleapis.com/oauth2/v4/token",
exp: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour expiration
iat: Math.floor(Date.now() / 1000),
};
export default async function fetchCell(cell: string, ...tags: string[]) {
const apiUrl = `https://sheets.googleapis.com/v4/spreadsheets/${env.SPREADSHEET_ID}/values/${cell}`;
const privateKey = await importPKCS8(env.GOOGLE_SA_PRIVATE_KEY, "RS256");
const token = await new SignJWT(payload)
.setProtectedHeader({ alg: "RS256" })
.setIssuedAt()
.setIssuer(env.GOOGLE_SA_CLIENT_EMAIL)
.setAudience("https://www.googleapis.com/oauth2/v4/token")
.setExpirationTime("1h")
.sign(privateKey);
// Form data for the token request
const form = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: token,
};
// Make the token request
const tokenResponse = await fetch(
"https://www.googleapis.com/oauth2/v4/token",
{
method: "POST",
body: JSON.stringify(form),
headers: { "Content-Type": "application/json" },
next: {
tags,
},
}
);
const tokenData = await tokenResponse.json();
// Use the access token to make the API request
const apiResponse = await fetch(apiUrl, {
headers: { Authorization: `Bearer ${tokenData.access_token}` },
next: {
tags,
},
});
const data = await apiResponse.json();
return data.values[0][0];
}Additional context
Add any other context or screenshots about the feature request here.
AaronFriel, dualdetail, kiikoh, rtrembecky, cogell and 7 more
Metadata
Metadata
Assignees
Labels
priority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.