Stay organized with collections
Save and categorize content based on your preferences.
A Topic resource represents a group of stream items categorized by
similarity, such as the week assigned or course subject.
Each topic is identified by a unique ID assigned by the server. Associated with
this ID is the course ID the topic belongs to, the actual topic name displayed
on the Classroom UI, and the date and time of the last update.
Create a topic
You can create a new topic in a course using the
topics.create() method, as shown in the following sample:
Topictopic=null;try{// Create the new Topic.Topiccontent=newTopic().setName("Semester 1");topic=service.courses().topics().create(courseId,content).execute();System.out.println("Topic id: "+topic.getTopicId()+"\n"+"Course id: "+courseId);}catch(GoogleJsonResponseExceptione){// TODO (developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The courseId does not exist: %s.\n",courseId);}else{throwe;}}catch(Exceptione){throwe;}returntopic;
Topictopic=null;try{// Get the topic.topic=service.courses().topics().get(courseId,topicId).execute();System.out.printf("Topic '%s' found.\n",topic.getName());}catch(GoogleJsonResponseExceptione){// TODO (developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The courseId or topicId does not exist: %s, %s.\n",courseId,topicId);}throwe;}catch(Exceptione){throwe;}returntopic;
List<Topic>topics=newArrayList<>();StringpageToken=null;try{do{ListTopicResponseresponse=service.courses().topics().list(courseId).setPageSize(100).setPageToken(pageToken).execute();/* Ensure that the response is not null before retrieving data from it to avoid errors. */if(response.getTopic()!=null){topics.addAll(response.getTopic());pageToken=response.getNextPageToken();}}while(pageToken!=null);if(topics.isEmpty()){System.out.println("No topics found.");}else{for(Topictopic:topics){System.out.printf("%s (%s)\n",topic.getName(),topic.getTopicId());}}}catch(GoogleJsonResponseExceptione){// TODO (developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The courseId does not exist: %s.\n",courseId);}else{throwe;}}catch(Exceptione){throwe;}returntopics;
Topictopic=null;try{// Retrieve the topic to update.TopictopicToUpdate=service.courses().topics().get(courseId,topicId).execute();// Update the name field for the topic retrieved.topicToUpdate.setName("Semester 2");/* Call the patch endpoint and set the updateMask query parameter to the field that needs to be updated. */topic=service.courses().topics().patch(courseId,topicId,topicToUpdate).set("updateMask","name").execute();/* Prints the updated topic. */System.out.printf("Topic '%s' updated.\n",topic.getName());}catch(GoogleJsonResponseExceptione){// TODO(developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The courseId or topicId does not exist: %s, %s.\n",courseId,topicId);}else{throwe;}}catch(Exceptione){throwe;}returntopic;
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 UTC."],[[["A topic in Google Classroom groups similar stream items together, identified by a unique ID, and includes information like the course it belongs to, its name, and the last updated timestamp."],["You can manage topics by creating, retrieving details (individually or as a list), updating the name of existing topics, and deleting them, using dedicated methods for each action."],["When creating or updating topics, ensure the name field is a non-empty string; avoid trailing spaces in topic names due to a known issue; and note that the topic ID and update time cannot be changed manually."],["Code samples in Java and Python are provided to illustrate how to interact with the Classroom API for various topic management operations."]]],[]]