Get youtube username given a channel id - youtube

Im trying to get username given the channel ID but the only thing that i get is channel title from snippet and this is not always the same. For instance:
Channel ID: UC2OTNzQ5tsg2eSf-D2mMJ8Q
Channel Title: ▂▃▅▆ Gmanlens29 ▆▅▃▂
User Name: Gmanlens29
Channel ID: UCgG6-eQtPhAdr3GxYEN0HJw
Channel Title: ►►Edvisss◄◄
User Name: Edwin01230
Is there a way to make this?
Thank you in advance,

I think you'll need to link up with the google+ api, use status.isLinked for checking if a channel ID is linked to google+ and contentDetails.googlePlusUserId to snag it.

The channel resource's contentDetails.googlePlusUserId property has been deprecated. Previously, the property was only present if the channel was associated with a Google+ profile. Following the deprecation, the property will no longer be included in any channel resources.

Related

How to collect images with a Whatsapp bot using Twilio

I've created a Whatsapp chat bot that collects various user information but I am unable to collect an image that a user sends. How can I do this? Is it a matter of using the right Field type, which I've tried doing but none of the default field's apply to images? Please help if anyone knows of a solution.
Heyooo. 👋 Twilio Developer Evangelist here.
If a User sends an image via Whatsapp the image URL will be available in the sent webhook. You can have a look at the payload the webhook includes:
body: {
MediaContentType0: 'image/jpeg',
SmsMessageSid: 'MM9...',
NumMedia: '1',
SmsSid: 'MM9...',
SmsStatus: 'received',
Body: '',
To: 'whatsapp:+141...',
NumSegments: '1',
MessageSid: 'MM9bc...',
AccountSid: 'ACa34...',
From: 'whatsapp:+49176...',
MediaUrl0: 'https://api.twilio.com/2010-04-01/Accounts/ACa34bb5d3c305d08ae1308786f4d79b72/Messages/MM9bc3...',
ApiVersion: '2010-04-01'
}
You'll find the NumMedia and MediaUrl0 property which includes the URL of the sent image. You can then download these images and do whatever you like with them.
To retrieve the image after the message and webhook were sent you can have a look at the MediaResource Docs. You can fetch media also programmatically with something along the following lines:
client.messages('MM...')
.media('ME...')
.fetch()
.then(media => console.log(media.contentType));
In case you're using Studio you can have a look at this tutorial which handles Whatsapp Media with a fun use case.
Let me know if that helps. 😊
(It's hard to give more advice because I'm not sure what you're trying to do.)

Optimize query to YouTube API

Help optimize YouTube API requests. The entire quota is spent in 5 minutes
Get id TOP 5 trends:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&key={token}&fields=items(id)&chart=mostPopular&regionCode=RU&maxResults=5
Get channel id and channel name from video id:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VideoId}&key={token}
Get channel name from username
https://www.googleapis.com/youtube/v3/channels?key={token}&forUsername={UserName}&part=id
Get channel image:
https://www.googleapis.com/youtube/v3/channels?id={ChannelId}&part=snippet&key={token}
Video count on channel:
​https://www.googleapis.com/youtube/v3/playlistItems?playlistId={ChannelId}&key={token}&part=snippet
Last video on channel:
https://www.googleapis.com/youtube/v3/search?key={token}&channelId={ChannelId}&part=id&order=date&maxResults=1
These are a few tips I think it might help:
Set specific fields to retrieve in each request.
The "search" request is the one who consumes more quota than the rest of your requests.
Here are your modified requests:
Get id TOP 5 trends - Demo:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&chart=mostPopular&hl=<REGION_CODE>&maxResults=5&fields=items%2Fid&key={YOUR_API_KEY}
Get channel id and channel name from video id: - demo
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=<VIDEO_ID>&fields=items(snippet(channelId%2CchannelTitle))&key={YOUR_API_KEY}
Get channel name from username (also bring at the same time the channel image and its count of uploaded videos) - demo
https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics&forUsername=<CHANNEL_USERNAME>&fields=items(snippet(thumbnails%2Ctitle)%2Cstatistics%2FvideoCount)&key={YOUR_API_KEY}
Last video on channel: - demo
Here you can use other approach:
Use the channel_id and replace the value as follows:
Channel: Microsoft Hololens:
Channel_id: UCT2rZIAL-zNqeK1OmLLUa6g
Uploads (playlist): UUT2rZIAL-zNqeK1OmLLUa6g
Once you get the uploads (playlist), use the following request:
https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=<UPLOAD_PLAYLIST>&fields=items(contentDetails(videoId%2CvideoPublishedAt))&key={YOUR_API_KEY}
And use the latest videoId from the response - (which has the most recent updated time).

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
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.
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

Can I use the Slack API to set the profile picture?

I am running a Slack team for a gaming community. My users all have avatars in the game and I am already using the Slack API to automatically set their Slack user name to their in-game name, so its easier for people to be recognized.
In addition I would also like to automatically set their profile picture in Slack with their avatar picture from the game. However I could not figure out a way to do it, so my question is can it be done and if yes, how?
My current starting point is the undocumented API method users.profile.set which allows me to set the profile of a user (see below for an example of a user profile). So far I've been able to modify:
first_name
last_name
title
phone
skype
The user profile also contains the URL to the profile picture, but I was so far not able to change it. I tried external URLs, and URLs of images already uploaded on Slack.
Here is a link to my documentation of the "undocumented" Slack API method users.profile.set with all options that I could figure out so far.
Any help would be hugely appreciated.
Update November 2017
In the meantime Slack has added a new API method called users.setPhoto for setting profile photos. However, this new method does not solve this question, because it only works for your own user (or more precisely the user you have an access token for, e.g. you not specify another user ID).
I am looking for a way to change the profile pictures of all users on my Slack team by a Slack app / bot.
Example of a user profile:
{
id: "U12345678",
team_id: "T12345678",
name: "erik.kalkoken",
deleted: false,
status: null,
color: "9f69e7",
real_name: "Erik Kalkoken",
tz: "America/Chicago",
tz_label: "Central Daylight Time",
tz_offset: 3600,
profile: {
avatar_hash: "XXX",
first_name: "Erik",
last_name: "Kalkoken",
title: "",
phone: "",
skype: "",
image_24: "https://avatars.slack-edge.com/2016-03-19/XXX_24.jpg",
image_32: "https://avatars.slack-edge.com/2016-03-19/XXX_32.jpg",
image_48: "https://avatars.slack-edge.com/2016-03-19/XXX_48.jpg",
image_72: "https://avatars.slack-edge.com/2016-03-19/XXX_72.jpg",
image_192: "https://avatars.slack-edge.com/2016-03-19/XXX_192.jpg",
image_512: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_1024: "https://avatars.slack-edge.com/2016-03-19/XXX_512.jpg",
image_original: "https://avatars.slack-edge.com/2016-03-19/XXX_original.jpg",
real_name: "Erik Kalkoken",
real_name_normalized: "Erik Kalkoken",
email: "test#email.com"
},
is_admin: false,
is_owner: false,
is_primary_owner: false,
is_restricted: false,
is_ultra_restricted: false,
is_bot: false,
has_2fa: false
}
After messing around with it for a little, it's possible to use the undocumented users.setPhoto endpoint:
curl https://slack.com/api/users.setPhoto \
-F "token=<removed>" \
-F "image=#/path/to/image.jpg"
Unfortunately it will resize your avatar which removes the ability to upload animated gifs.
I don't think the profile picture API is available yet. I read a while back that it was on their TODO list.
I was able to get it to work using Jay Querie's method.
The two difference was I gave the full path and I put the image first.
So in my case:
curl https://slack.com/api/users.setPhoto -F "image=#C:\Users\name\Pictures\dojocat.jpg" -F "token=xxxx-123-123-123-123"
Originally when I was using gitbash to run the curl and it was searching for the image in the directory where my gitbash was installed / being executed. So if I put the dojocat.jpg next to my gitbash executable it would would have found it.

How can I get a channel ID from YouTube?

I'm trying to retrive the data from my channel using the YouTube Data API V3.
For that I need my channel ID.
I've tried to find my channel ID from my YouTube account, and I failed in every single way.
If anyone have a single tip for me, I would be incredible glad.
This is the URL that I'm using to retrieve the data:
https://www.googleapis.com/youtube/v3/channels?id=fjTOrCPnAblTngWAzpnlMA&key={YOUR_API_KEY}&part=snippet,contentDetails,statistics
The ID is for the channel ID, and the key, I'm replacing the {YOUR_API_KEY} with my API KEY generated at my Google API console.
My channel ID is not:
- klauskkpm
- klausmachado
- klausmachado#gmail.com
- fjTOrCPnAblTngWAzpnlMA
My channel is: http://www.youtube.com/user/klauskkpm
To obtain the channel id you can view the source code of the channel page and find either data-channel-external-id="UCjXfkj5iapKHJrhYfAF9ZGg" or "externalId":"UCjXfkj5iapKHJrhYfAF9ZGg".
UCjXfkj5iapKHJrhYfAF9ZGg will be the channel ID you are looking for.
An easy answer is, your YouTube Channel ID is UC + {YOUR_ACCOUNT_ID}.
To be sure of your YouTube Channel ID or your YouTube account ID, access the advanced settings at your settings page
And if you want to know the YouTube Channel ID for any channel, you could use the solution #mjlescano gave.
https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername={USER_NAME}&part=id
If this could be of any help, some user marked it was solved in another topic right here.
You can get the channel ID with the username (in your case "klauskkpm") using the filter "forUsername", like this:
https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername=klauskkpm&part=id
More info here: https://developers.google.com/youtube/v3/docs/channels/list
At any channel page with "user" url for example http://www.youtube.com/user/klauskkpm, without API call, from YouTube UI, click a video of the channel (in its "VIDEOS" tab) and click the channel name on the video. Then you can get to the page with its "channel" url for example https://www.youtube.com/channel/UCfjTOrCPnAblTngWAzpnlMA.
I just found the simplest way to find the channel ID of any YouTube channel !!
Step 1: Play a video of that channel.
Step 2: Click the channel name under that video.
Step 3: Look at the browser address bar.
June 2021 edition.
Right click and view page source.
Search for "externalId", the value follows.
Source: comment by Daniel 2017.
Alternative: run this JavaScript in console:
ytInitialData.metadata.channelMetadataRenderer.externalId
An alternative to get youtube channel ID by channel url without API:
function get_youtube_channel_ID($url){
$html = file_get_contents($url);
preg_match("'<meta itemprop=\"channelId\" content=\"(.*?)\"'si", $html, $match);
if($match && $match[1])
return $match[1];
}
As of 2022-06-23:
Open Chrome Dev Tools (F12), and in the "Elements" tab, within the source code pane, depending on URL type:
A. For channel URLs of type: www.youtube.com/c/<channel_name>:
Search for either:
"externalId" - next to it there will be the channel_ID
"channelUrl" - next to it there will be: https://www.youtube.com/channel/<channel_ID>
or run in the console:
ytInitialData.metadata.channelMetadataRenderer.externalId
(credit: https://stackoverflow.com/a/68063136/624597)
B. For video URLs of type: www.youtube.com/watch?v=<video_ID>:
Search for either:
"externalId" - next to it there will be the channel_ID
"externalChannelId" - next to it there will be the channel_ID
"ownerProfileUrl" - next to it there will be: https://www.youtube.com/channel/<channel_ID>
or run in the console:
ytInitialPlayerResponse.microformat.playerMicroformatRenderer.externalChannelId
Channel id with the current youtube version is obtained very easily if you login to YouYube website and select 'My channel'
Your channel ID will be displayed on the address bar of your browser
https://www.youtube.com/account_advanced now provides both channel and user ids. See also https://developers.google.com/youtube/v3/guides/working_with_channel_ids .
2017 Update: Henry's answer may be a little off the mark here. If you look for data-channel-external-id in the source code you may find more than one ID, and only the first occurrence is actually correct. Get the channel_id used in <link rel="alternate" type="application/rss+xml" title="RSS" href="https://www.youtube.com/feeds/videos.xml?channel_id=<VALUE_HERE"> instead.
To obtain the channel id you can do the following request which gives you the channel id and playlist id.
https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2C+statistics%2Csnippet&mine=true&key={YOUR_API_KEY}
mine parameter means the current authorized user
as u said channel id is prefixed with UC+{your account id} which you get while login, you can use this one also without requesting the above url you can directly call the channel api with your google id and just prefix with UC
https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2C+statistics%2Csnippet&id=UC{your account id}&key={YOUR_API_KEY}
Apparently there is a channelId attribute in video page's source code;
To get Channel id
Ex: Apple channel ID
Select any of the video in that channel
Select iPhone - Share photos (video)
Now click on channel name Apple bottom of the video.
Now you will get channel id in browser url
Here this is Apple channel id : UCE_M8A5yxnLfW0KghEeajjw
Try to search for regular expression UC[-_0-9A-Za-z]{21}[AQgw] in source code. This ID is presented even if channel has non-ASCII characters in URL:
Here is screenshot of internal viewer/editor of Midnight Commander, it has regexp search:
Alternatives to get the channel URL with its ID.
With a CSS selector by searching the channel homepage source code:
body > link[rel="canonical"]
or with JS via the console:
document.querySelector('body > link[rel="canonical"]').href
Another method to find the ID of a channel that is not yours is to go to the channel page and press the red "Subscribe" button.
Then use the Chrome's Inspector tools Network tab and look for the POST request issued by the subscribe action. In the payload of this request you will find the channel id:
You can unsubscribe immediately after subscribing.
Now in 2023, typing this in console should work:
document.querySelectorAll('[itemprop="channelId"]')[0].content

Resources