i'm trying to intergrate Google Form API in my app. I want to show response of question and answers. I log responseURL and this is what i received:
request: {
responseURL: 'https://forms.googleapis.com/v1/forms/131QG6skV-e6PztX0x7IKrXaRA8shh9XGjJKH1RyelO4/responses'
}
When i click on this responseURL link, this is what i got :
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"method": "google.apps.forms.v1.FormsService.ListFormResponses",
"service": "forms.googleapis.com"
}
}
]
}
}
My headers still have bearer accesstoken. How do I fix this problem? Thanks everyonee. Here my code :
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { google } from 'googleapis';
import { requestBodyForm } from 'src/shared/hepler/google-form-data';
@Injectable()
export class FormService {
constructor(private readonly configService: ConfigService) {}
async createForm(titleForm: string) {
const CLIENT_ID = this.configService.get('CLIENT_ID');
const CLIENT_SECRET = this.configService.get('CLIENT_SECRET');
const REDIRECT_URI = this.configService.get('REDIRECT_URI');
const REFRESH_TOKEN = this.configService.get('REFRESH_TOKEN');
const oauth2Client = new google.auth.OAuth2(
CLIENT_ID,
CLIENT_SECRET,
REDIRECT_URI,
);
oauth2Client.setCredentials({ refresh_token: REFRESH_TOKEN });
const form = google.forms({
version: 'v1',
auth: oauth2Client,
});
const newForm = {
info: {
title: titleForm,
},
};
const createResponse = await form.forms.create({
requestBody: newForm,
});
const formId = createResponse.data.formId;
const updateForm = await form.forms.batchUpdate({
formId,
// requestBody: update,
requestBody: requestBodyForm,
});
const res = await form.forms.responses.list({
formId,
});
console.log(res);
}
}