Activities
Learn about the activities resource and how to use it to get a response from an API call.
We'll cover the following
The activities
resource is mainly used to track each operation performed by the user’s own channel or a channel on YouTube, such as commenting on a video, rating a video, or adding a video to a playlist.
List activities
We can call the endpoint by sending a GET
request to the following URL:
https://www.googleapis.com/youtube/v3/activities
Note: This resource only offers the listing method for the activities.
Request parameters
Some important request parameters to call the endpoint are as follows:
Name | Type | Category | Description |
| String | Required | This parameter will be used to specify the response field properties, which are |
| String | Optional | Used to specify which channel activities are required. |
| Boolean | Optional | Used to restrict fetches so that data is uploaded by the user. |
| Integer | Optional | Used to fix the number of results that will be fetched. |
| String | Optional | Used to specify the page in the response. |
| Datetime | Optional | Used to specify a date and time to fetch results after the specified time. |
| Datetime | Optional | Used to specify a date and time to fetch results before the specified time. |
| String | Optional | Used to identify the activities of a specific region. |
Click the “Edit” button in the following widget, enter the channel ID in the CHANNEL_ID
field, and click the “Save” button. After saving the keyword, click the “Run” button to retrieve the activity results.
Note: Look at the steps in the Find the Chanel ID lesson in the Appendix to find the channel ID.
// Importing libraries hereimport fetch from 'node-fetch';// Define endpoint URL hereconst endpointUrl = new URL('https://www.googleapis.com/youtube/v3/activities');// Define Header Parameters hereconst headerParameters = {Authorization: 'Bearer {{ACCESS_TOKEN}}',Accept: 'application/json',};// Define Query Parameters hereconst queryParameters = new URLSearchParams({part: 'snippet,contentDetails',channelId: '{{CHANNEL_ID}}',});// Setting API call optionsconst options = {method: 'GET',headers: headerParameters,};// Function to make API callasync function listingActivities() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API calllistingActivities();
Let’s take a look at the following code explanation:
Line 5: We define a variable with the name
endpointUrl
in which we pass the endpoint URL.Lines 14–17: We define a variable with the name
queryParameters
in which we define thechannelId
parameter. ThechannelId
parameter is used to pass that channel ID. Activities are required.
Note: We can also fetch the user activities by simply using the
mine
parameter instead ofchannelId
.
Response fields
Name | Type | Description |
| String | Reflects the resource type of the API call. |
| ETag | Contains the resource ETag. |
| String | Used to fetch the next page in the response result. |
| Sstring | Used to fetch the previous page in the response result. |
| Object | Contains the response page information. |
| List | Contains the list of results that matches the request requirement. |