2

I'm trying to integrate google classroom API where student can submit their work on a particular assignment and then update the state to hand in/turn in. I'm using turn in API endpoint but the API doesn't update the state nor return any response.

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { google, classroom_v1, Auth } from 'googleapis';
@Injectable()
export class GoogleApiService {
  oauth2Client: Auth.OAuth2Client;
  classroom: classroom_v1.Classroom;
  constructor(private configService: ConfigService) {
    const clientId = this.configService.get('GOOGLE_CLIENT_ID');
    const clientSecret = this.configService.get('GOOGLE_SECRET_KEY');
    const redirectUrl = this.configService.get('GOOGLE_REDIRECT_URL');

    this.oauth2Client = new google.auth.OAuth2(
      clientId,
      clientSecret,
      redirectUrl,
    );

    google.options({
      http2: true,
    });

    this.classroom = google.classroom({
      version: 'v1',
      auth: this.oauth2Client,
    });
  }

  setRefreshToken(token: string) {
    this.oauth2Client.setCredentials({
      refresh_token: token,
    });
  }

  async turnIn(courseId: string, courseWorkId: string, submissionId: string) {
    try {
      const turnInParam: classroom_v1.Params$Resource$Courses$Coursework$Studentsubmissions$Turnin =
        {
          courseId,
          courseWorkId,
          id: submissionId,
        };
      const res =
        await this.classroom.courses.courseWork.studentSubmissions.turnIn(
          turnInParam,
        );
      return res;
    } catch (error) {
      console.log(error);
      return false;
    }
  }
}

after this nothing executes.

 const res =
        await this.classroom.courses.courseWork.studentSubmissions.turnIn(
          turnInParam,
        );

0 Answers0