googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.42k stars 1.92k forks source link

How to use courses.courseWork.addOnAttachments resource? #3529

Open MuhamadIsmuaji opened 3 months ago

MuhamadIsmuaji commented 3 months ago

Hello everyone may I ask how I can use courses.courseWork.addOnAttachments resource with this lib? I've installed the lib with yarn install googleapis with version 140.0.1 or yarn install @googleapis/classroom with version 4.0.9. But somehow I can't use like google.classroom({ version: 'v1' }).courses.courseWork.addOnAttachments.create() ? I've see in this repo there is addOnAttachments in this code . But somehow when I've install the lib, I can't find that code

lukesanborn commented 3 months ago

I'm having the same problem too. Google API clients are automatically generated from a discovery JSON file. Google must periodically re-generate each client library and push to the respective package manager, npm, pypi etc. For example, the Python client API was regenerated a few weeks ago and includes Google Classroom Add-on functionality. The nodejs client library has not been regenerated with these new classroom changes. I've found a workaround to get these working locally if you're interested.

Google if you are seeing this, please update the npm package 🙏

MuhamadIsmuaji commented 3 months ago

I'm having the same problem too. Google API clients are automatically generated from a discovery JSON file. Google must periodically re-generate each client library and push to the respective package manager, npm, pypi etc. For example, the Python client API was regenerated a few weeks ago and includes Google Classroom Add-on functionality. The nodejs client library has not been regenerated with these new classroom changes. I've found a workaround to get these working locally if you're interested.

Google if you are seeing this, please update the npm package 🙏

Hi @lukesanborn thanks for the response. Yep I'm interested for how it can working locally, could you please let me know?

lukesanborn commented 3 months ago

Workaround steps: Clone git repo -> google-api-nodejs-client/generator.md at main · googleapis/google-api-nodejs-client (github.com) cd google-api-nodejs && npm i ** important check to make sure you have the right discovery file

node build/src/generator/generator.js 'https://classroom.googleapis.com/$discovery/rest' \ --include-private false \ --use-cache false

After generating the API, install the package cd src/apis/classroom Npm i && npm pack That should create “googleapis-classroom-4.0.9.tgz” Then move the file to your source code Add this line to the package. json file
"classroom-with-addon": "file:./googleapis-classroom-4.0.9.tgz", Run npm i and now should work :)))

MuhamadIsmuaji commented 3 months ago

Also @lukesanborn maybe you know about this problem as well, I've try to issue request using Axios. Somehow I always got error below { "error": { "code": 403, "message": "@ProjectPermissionDenied The Developer Console project is not permitted to make this request.", "status": "PERMISSION_DENIED" } }

So what I've done is try to create attachment with issue POST request with Axios to https://classroom.googleapis.com/v1/courses/${courseId}/courseWork/${itemId}/addOnAttachments. I use axios config headers below

headers: { "Content-Type": "application/json", Authorization:Bearer ${accessToken}, }, I use OAuth 2.0 credentials and I've make sure all scopes already configured

MuhamadIsmuaji commented 3 months ago

Btw thanks for the workaround steps @lukesanborn , let me try it

lukesanborn commented 3 months ago

Have you enabled the Google Classroom API in the Cloud console? @MuhamadIsmuaji

MuhamadIsmuaji commented 3 months ago

Yes @lukesanborn , Google Classroom API already enabled. Additional information, I can issue GET request with Axios with same config to https://classroom.googleapis.com/v1/courses

lukesanborn commented 3 months ago

@sofisl When will the package be updated on npm?