How do you use Google API getRequestHeaders() to get an OAuth2 access token?
This new function directly gives you an 'Headers' object:
{ Authorization: 'Bearer xxxxxxxxx' }
So you can happend it directly use it as your header object:
const authHeaders = await this.auth.getRequestHeaders();
yourfetchlibrary.get('https://......', {
headers: authHeaders,
})
Or extract the Authorization part:
const authHeaders = await this.auth.getRequestHeaders();
yourfetchlibrary.get('https://......', {
headers: {
'Authorization': authHeaders.Authorization,
'Content-Type': 'application/json',
},
})
const accessToken=oAuth2Client.getAccessToken()
This worked for me