Activities
Explore how to use the YouTube Data API to track operations performed on your YouTube channel, including commenting, rating, and adding videos to playlists. Learn to call the Activities endpoint with appropriate parameters to retrieve user activity data effectively.
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.
Let’s take a look at the following code explanation:
Line 5: We define a variable with the name
endpointUrlin which we pass the endpoint URL.Lines 14–17: We define a variable with the name
queryParametersin which we define thechannelIdparameter. ThechannelIdparameter is used to pass that channel ID. Activities are required.
Note: We can also fetch the user activities by simply using the
mineparameter 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. |