Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Eine Themenressource stellt eine Gruppe von Streamelementen dar, die nach Ähnlichkeit kategorisiert sind, z. B. nach der zugewiesenen Woche oder dem Kursfach.
Jedem Thema wird eine eindeutige ID zugewiesen, die vom Server vergeben wird. Mit dieser ID sind die Kurs-ID, zu der das Thema gehört, der tatsächliche Themenname, der in der Classroom-Benutzeroberfläche angezeigt wird, sowie das Datum und die Uhrzeit der letzten Aktualisierung verknüpft.
Thema erstellen
Mit der Methode topics.create() können Sie ein neues Thema in einem Kurs erstellen, wie im folgenden Beispiel gezeigt:
List<Topic> topics = new ArrayList<>();
String pageToken = null;
try {
do {
ListTopicResponse response =
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 (Topic topic : topics) {
System.out.printf("%s (%s)\n", topic.getName(), topic.getTopicId());
}
}
} catch (GoogleJsonResponseException e) {
// TODO (developer) - handle error appropriately
GoogleJsonError error = e.getDetails();
if (error.getCode() == 404) {
System.out.printf("The courseId does not exist: %s.\n", courseId);
} else {
throw e;
}
} catch (Exception e) {
throw e;
}
return topics;
Python
topics = []
page_token = None
while True:
response = service.courses().topics().list(
pageToken=page_token,
pageSize=30,
courseId=<course ID or alias>).execute()
topics.extend(response.get('topic', []))
page_token = response.get('nextPageToken', None)
if not page_token:
break
if not topics:
print('No topics found.')
else:
print('Topics:')
for topic in topics:
print('{0} ({1})'.format(topic['name'], topic['topicId']))
Themen aktualisieren
Sie können den Namen eines vorhandenen Themas mit der Methode topics.patch() aktualisieren, wie im folgenden Beispiel gezeigt:
Topic topic = null;
try {
// Retrieve the topic to update.
Topic topicToUpdate = 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 (GoogleJsonResponseException e) {
// TODO(developer) - handle error appropriately
GoogleJsonError error = e.getDetails();
if (error.getCode() == 404) {
System.out.printf("The courseId or topicId does not exist: %s, %s.\n", courseId, topicId);
} else {
throw e;
}
} catch (Exception e) {
throw e;
}
return topic;
Python
topic = {
"name": "New Topic Name"
}
response = service.courses().topics().patch(
courseId=<course ID or alias>,
id=<topic ID>,
updateMask="name",
body=topic).execute()
print('{0} ({1})'.format(response['name'], response['topicId']))
Themen löschen
Sie können ein vorhandenes Thema mit der Methode topics.delete() löschen, wie im folgenden Beispiel gezeigt:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-11-23 (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."]]],[]]