3

I am using the Classroom Share Button to let users create assignments with resources from my Website on Google Classroom.

Is it possible to retrieve the courseId and the courseWorkId of the newly created assignment? I need this info to be able to store it on my website and reuse it later.

I already tried to use the callback "onsharecomplete", but it does not seem to get the required info as parameter. I also could not find any documentation about the arguments of this method.

My HTML looks like this:

<script src="https://apis.google.com/js/platform.js" async defer></script>
<div id="google-classroom-div">
  <div className="g-sharetoclassroom" data-size="32" data-url="https://www.example.com" data-onsharecomplete="onShareComplete"></div>
</div>

And the javascript to render the button and handle the callback looks like this:

gapi.sharetoclassroom.go("google-classroom-div");
window.onShareComplete = (arg1, arg2) => {
  console.log(arg1); // is undefined
  console.log(arg2); // contains some weird data
};

I know that there is another way to create assignments by using the Classroom API, i.e. the REST Resource v1.courses.courseWork.create but then I would have to create the UI for choosing the course and posting the assignment on my own which I would like to avoid.

StefanLi
  • 31
  • 2
  • That would be the closest workaround you can do. Using the Rest API, you can have the freedom to create a complex function that you can customize. You can follow the quickstart sample for [javascript](https://developers.google.com/classroom/quickstart/js) to be guided on how to a simple browser application that makes requests to the Classroom API. Hope this helps. – Mr.Rebot Oct 11 '17 at 15:41

0 Answers0