Multicoder
Multicoder

Reputation: 3

youtube api - get timestamp of subscription

I am fetching all the Accounts that have subscribed to the authenticated user's channel. Is there a way to obtain the timestamp of when the user has subscribed to the channel?

The default "publishedAt" sadly is of no help because that seems to be the timestamp of when the channel was created. Also, that is not part of the "subscriberSnippet"-Section

Twitch and Mixer both provide "created_at", but the YouTube-API is a whole other story...

Thank you very much, ~ Daniel

Upvotes: 0

Views: 658

Answers (2)

Marek
Marek

Reputation: 1543

Yes, here's an example in Python

import requests

headers = {
    'Authorization': 'Bearer {0}'.format(token),
    'Client-Id': client_id
}
query = {
    'part': 'subscriberSnippet,snippet',
    'mySubscribers': 'true',
    'key': youtube_key
}
if cursor is not None:
    query['pageToken'] = cursor
response = requests.get(
    'https://youtube.googleapis.com/youtube/v3/subscriptions',
    headers=headers, params=query)
res = response.json()

weirdly, snippet contains your authenticated user channel description and title but publishedAt field corresponds to when the item from subscriberSnippet subscribed to your authenticated user

Upvotes: 0

Jessica Rodriguez
Jessica Rodriguez

Reputation: 2974

Based from the official documentation of Youtube API:

Subscriptions: list

  • retrieves a list of channels that the specified channel subscribes to.

You can view here the subscriptions resource and publishedAt is part of it:

snippet.publishedAt datetime

The date and time that the subscription was created. The value is specified in ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) format.

You can try the try this section from the documentation and check your Youtube Subscibers List using Creator Studio by following the steps here.

Note: The list only shows subscribers who have chosen to make their subscriptions public. When a user first joins YouTube, their subscriptions list is set to private by default.

Upvotes: 1

Related Questions