I need help understanding determining Youtube username/channel name when you only have the channel ID - youtube-api

So according to https://developers.google.com/youtube/v3/guides/working_with_channel_ids, every account contains a unique channel ID which is independent to what used to be a username. That's all fine and dandy, as channel ID is the way to identify unique accounts. Sure, I'm all for that. Where I am confused, is when I am given a unique channel ID, how can I use this to obtain the channels preferred "username", whether it be some online alias or "real-life" name?
Specifically, I am using this API (https://developers.google.com/youtube/v3/live/docs/liveChatMessages/list?hl=en) to periodically watch as new messages are placed into my broadcast. It works, and provides data which looks like the following:
{
kind: 'youtube#liveChatMessage',
etag: 'zPV9PwBFYCiNZH_4PpspXF0ZrSs',
id: 'LCC.CikqJwoYVUNMcnBlSWl1aVF1WHphcldCZVFuc3dBEgtOaHI4d2NSUHIyQRI5ChpDTC0ybDQzcC12TUNGVVFCZlFvZDVBQUhiQRIbQ09YRjdfM2stdk1DRmZRYmZRb2QzT0FCUUEw',
snippet: {
type: 'textMessageEvent',
liveChatId: 'KicKGFVDTHJwZUlpdWlRdVh6YXJXQmVRbnN3QRILTmhyOHdjUlByMkE',
authorChannelId: 'UCLrpeIiuiQuXzarWBeQnswA',
publishedAt: '2021-11-02T23:22:37.070185+00:00',
hasDisplayContent: true,
displayMessage: 'testing once again 😀',
textMessageDetails: [Object]
}
}
As you can see, there is an authorChannelId here, which is great... Except for the fact that I can't reasonably read this as a human.
My use case is that I specifically want to have a periodically updating local app which can update me with a console message similarly formatted like so:
Bob Frank: foo bar :D
Even though I technically can have something like the following, it doesn't help me know which of my 5 friends I'm expecting in my live broadcast:
UCLrpeIiuiQuXzarWBeQnswA: foo bar :D
Ah yes... Who are you again? Can you remind me again UCLrpeIiuiQuXzarWBeQnswA?
I have also tried the following API (https://developers.google.com/youtube/v3/docs/channels/list), but it doesn't appear to give the right information either. With part: "snippet" and id: "UCLrpeIiuiQuXzarWBeQnswA" I get the following output:
{
config: {
url: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA',
method: 'GET',
userAgentDirectives: [ [Object] ],
paramsSerializer: [Function (anonymous)],
headers: {
'x-goog-api-client': 'gdcl/5.0.5 gl-node/17.0.1 auth/7.10.1',
'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/5.0.5 (gzip)',
Authorization: 'Bearer',
Accept: 'application/json'
},
params: { part: 'snippet', id: 'UCLrpeIiuiQuXzarWBeQnswA' },
validateStatus: [Function (anonymous)],
retry: true,
responseType: 'json'
},
data: {
kind: 'youtube#channelListResponse',
etag: 'wjX6CX2hdUPFAc4y6OCUDDjXT6o',
pageInfo: { totalResults: 1, resultsPerPage: 5 },
items: [ [Object] ]
},
headers: {
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
'cache-control': 'private',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Wed, 03 Nov 2021 01:30:32 GMT',
server: 'scaffolding on HTTPServer2',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin, Referer',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0'
},
status: 200,
statusText: 'OK',
request: {
responseURL: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA'
}
}
So, any help would be greatly appreciated! Thanks!
Edit: removed access token. Whoops.
Edit2: Answer was in the question, but helped by the accepted answer below. Thank you Benjamin! The real answer is to go further into the final response above.... response.data.items[0].snippet.title. nodejs console.log() in this case did not expand each item and I totally missed this detail. My bad, I'm a novice in node and javascript. You can also use the API key as Benjamin points out, but at this point I've already got access to Oauth2 so I'll keep using the same auth.

Indeed Channels: list is the way to go.
Just by accessing and parsing the JSON at this URL https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=A_CHANNEL_ID&key=YOUR_API_KEY. It has a field "title" in its "snippet" which seems to be exactly what you want.
Of course you have to change A_CHANNEL_ID with, an authorChannelId, UCLrpeIiuiQuXzarWBeQnswA for instance.

Related

creating jira customfield issue

Does anyone have an idea of creating an array and option type customfield issue ?
If anyone does have leads, please suggest some.
although i tried to do some changes around here but no luck.
(customfield_15101={"value": target_department})
----------main error---------
text: data was not an array
url: http://jira/rest/api/2/issue
response headers = {'X-AUSERNAME': 'rest_api', 'X-ASEN': 'SEN-2710437', 'X-XSS-Protection': '1; mode=block', 'Content-Security-Policy': "frame-ancestors 'self'", 'X-Content-Type-Options': 'nosniff', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'X-AREQUESTID': '362x28422825x1', 'X-ASESSIONID': 'xhojwj', 'Connection': 'close', 'Cache-Control': 'no-cache, no-store, no-transform', 'Date': 'Thu, 18 Aug 2022 05:02:01 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Server': 'Apache/2.4.6 (CentOS) PHP/5.4.16', 'Content-Type': 'application/json;charset=UTF-8', 'Access-Control-Allow-Origin': '*'}
response text = {"errorMessages":[],"errors":{"Target Department/s":"data was not an array"}}
issue = JIRA_INTERFACE.create_issue(customfield_15101={"value": target_department})
jira meta for this customfield:
{"type":"array","items":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multiselect","customId":15101},"name":"Target Department/s","hasDefaultValue":false,"operations":["add","set","remove"],"allowedValues":[{"self":"http://jira/rest/api/2/customFieldOption/14189","value":"All Departments","id":"14189"},
although i tried to use
issue = JIRA_INTERFACE.create_issue(customfield_15101={"value":"RPM"})
but no luck
issue = JIRA_INTERFACE.create_issue(customfield_15101={u"value":u"RPM"})
whenever you try to create issue, first retrieve values and check whether the value are unicode.

slack send message [ERROR] missing required field: channel

I am trying to test sending message to channel via bot (App, to be exact.)
My query in Postman:
https://slack.com/api/chat.postMessage/ (there is token in headers)
and body
{"channel":"XXX","text":"I hope the tour went well, Mr. Wonka."}
But as result
{
"ok": false,
"error": "invalid_arguments",
"response_metadata": {
"messages": [
"[ERROR] missing required field: channel"
]
}
}
I had the same issue and my problem was that I was doing GET instead of POST. Now it works for me.
Please check your content-type header. It should be "application/json" instead of "plain/text"
I had to set
content-type: "application/json; charset=utf-8"
The charset mattered.
For myself, I was getting this because I was calling
POST https://slack.com/api/chat.postMessage/
The issue is in the last /. So the correct call is:
POST https://slack.com/api/chat.postMessage
EXTRA:
Here are my headers:
{
'Content-Type': 'application/json',
'charset': 'utf-8',
'Authorization': 'Bearer {YOUR_BOT_TOKEN_INSIDE_WITHOUT_CURLY_BRACKETS}'
}
and my body (make sure to put the # before the name of the channel).
{
'test': 'YOUR_TEXT_MESSAGE_IN_HERE',
'channel': '#{YOUR_CHANNEL_NAME_WITHOUT_CURLY_BRACKETS}'
}

Is there a way to change the Content Type for a Postman OAuth 2 Client Credentials request?

I'm trying to use the built in tool to get an OAuth 2.0 token for my requests. This seems pretty straightforward when reading the documentation and I set it up like this:
The issue is that the request for the token is sent with a content type of application/x-www-form-urlencoded. So the response I'm getting from the server is a 415 Unsupported Media Type I do not see a way to change the request content-type to application/json.
Am I missing something or is the only way to create a custom pre-request script?
https://github.com/oauthjs/node-oauth2-server/issues/92
application/x-www-form-urlencoded , is the supported content-type for Oauth
https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3
If you want to create , you can use pre-requisite script something like:
https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990
// Refresh the access token and set it into environment variable
pm.sendRequest({
url: pm.collectionVariables.get("zoho_accounts_endpoint") + "/oauth/v2/token",
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "client_id", value: pm.collectionVariables.get("zoho_client_id"), disabled: false},
{key: "client_secret", value: pm.collectionVariables.get("zoho_client_secret"), disabled: false},
{key: "refresh_token", value: pm.collectionVariables.get("zoho_refresh_token"), disabled: false},
{key: "grant_type", value: 'refresh_token', disabled: false}
]
}
}, function (err, res) {
pm.collectionVariables.set("zoho_access_token", 'Zoho-oauthtoken ' + res.json().access_token);
});
Change it to JSON or what ever you want and store the value to a variable and use that as bearer {{token}}

Possible bug when adding a newly created video to a playlist

As of recently, a script has been reporting failures when trying to add a newly created youtube video to a playlist.
The flow is pretty simple:
URL being requested: POST https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&alt=json&part=status%2Csnippet
Video id 'ABC123' was successfully uploaded.
Adding ABC123 to playlist MyPlaylistId
URL being requested: POST https://www.googleapis.com/youtube/v3/playlistItems?alt=json&part=snippet
Payload:
{"snippet": {"resourceId": {"kind": "youtube#video", "videoId": "ABC123"}, "playlistId": "MyPlaylistId"}}
Response:
{'status': '404', 'content-length': '226', 'x-xss-protection': '0', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'vary': 'Origin, X-Origin, Referer', 'server': 'scaffolding on HTTPServer2', '-content-encoding': 'gzip', 'cache-control': 'private', 'date': 'Thu, 17 Sep 2020 12:13:36 GMT', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"', 'content-type': 'application/json; charset=UTF-8'}
Response content:
{
"error": {
"code": 404,
"message": "Video not found.",
"errors": [
{
"message": "Video not found.",
"domain": "youtube.playlistItem",
"reason": "videoNotFound"
}
]
}
}
Now, the funny part is that the video is actually successfully added to the playlist. I have tested it several times and I get the same result.
Can anyone confirm this bug?
It seems indeed a bug, but, as far as I know, the site for post about bugs with the YouTube APIs is: Issue Tracker1.
The following link allows you create an entry on Issue Tracker.
It is worth check first if entries exists with the similar issue you're facing and if you find related entries there, please "star" that issue to draw attention to it and track updates, if you'd like.
1 Issue Tracker is shown (alongside Stack Overflow) at the end of the page of YouTube Data API website.

422 error when creating a ticket in Zendesk

I am developping an app in ASP.NET MVC5 using Zendesk_v2 (uploaded using a nuget package). I have admin rights for subdomain easynext.zendesk.com.
Here is my code for creating a ticket:
private static string requestUri = "https://easynext.zendesk.com/api/v2/tickets.json";
private static string _username = "gbalasel#easynext.be";
private static string _password = "MYPASSWORD";
private static ZendeskApi apiZendesk = new ZendeskApi(requestUri, _username, _password, "");
private void CréerTicketZendesk() {
var myTicket = apiZendesk.Tickets.CreateTicket(new Ticket()
{
Subject = "test ticket",
Priority = TicketPriorities.Low
});
}
This code sends me a 422 Unprocessable Entity error.
I have also made a test account for a client in Zendesk and the method works fine, the ticket is created in Zendesk and I also receive it in my email account.
Status 422 is most likely caused by a semantic error on your part. In my experience, ZD can return 422 most often in two situations:
When trying to PUT an update to a ticket whose status is closed. In that case, you need to create a new ticket or a follow-up ticket, if possible.
Setting an invalid value on some attribute of the ticket object or sub-object of the ticket. This can be particularly tedious to debug, as the ZD response doesn't usually tell you which attribute has an invalid value. You should check all the integer values that you are setting on the ticket. E.g., I've been burned by using the Group IDs from my production Zendesk while developing on the Sandbox System (they most likely have entirely different IDs for everything, including custom fields, groups, users, etc.).
If you are creating new tickets via POST, be sure to check all the values you are setting, as per my second bullet point above.
This telling you that you have not formed a request that it can handle; the destination script exists (otherwise you'd see a 404), the request is being handled (otherwise you'd get a 400 error) and it's been encoded correctly (or you'd get a 415 error) but the actual instruction can't be carried out.
take a look on this for more info.
Error List
just to add to the solution if anyone encounters the same problem.
requester_id is mandatory while posting the ticket json.
A sample ticket json -
{
"ticket": {
"subject": "My printer is on fire!",
"requester_id": 123,
"assignee_id": 456,
"type": "incident",
"subject": "Help, my printer is on fire!",
"description": "The fire is very colorful.",
"priority": "High",
"status": "open",
"custom_fields": [
{
"id": 111, // custom field ID
"value": "500.23"
}
]
}
}
Thanks
Yeah I run today to the same problem and solved it. The problem is that you need a comment and body part inside the ticket structure.
So this is how it could look like (in PHP):
$ticket = [
'group_id' => '35135',
'title' => 'Title',
'subject' => 'Subject',
'type' => 'ticket',
'comment' => ['body' => 'Comment text.'],
'priority' => 'normal',
'ticket_form_id' => '454524',
'custom_fields' => [
'51325351' => 'test',
],
];
Take a look on here:
https://developer.zendesk.com/rest_api/docs/core/tickets
I had an issue with the Zendesk API throwing a 422 when I was attempting to create a ticket. All parameters were correct, the problem was that the assignee for which the ticket was created for did not belong to the group.
I found this error by looking at the request response by using FIDDLER.
Adding this here in case someone else runs into this issue. For me the ticket formatting was correct, but the requester was suspended:
Error Result:
{
"error": "RecordInvalid",
"description": "Record validation errors",
"details": {
"requester": [{
"description": "Requester: jkraft is suspended."
}]
}
}
Follow these instructions to unsuspend a user: https://support.zendesk.com/hc/en-us/articles/4408835668634-How-do-I-unsuspend-access-for-a-user-
I hope this is helpful to tell whether or not you are receiving the HTTP 422 because the ticket was already closed or if its because you were trying to do something like edit a field with invald params:
If you log the response object from zendesk for the failed http 422, you can look at the response object and check its configs. In my example it was:
response: {
status: 422,
statusText: 'Unprocessable Entity',
headers: {
date: 'Wed, 01 Feb 2023 17:48:00 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '145',
connection: 'close',
'x-zendesk-api-version': 'v2',
'x-zendesk-application-version': 'v15375',
'x-frame-options': 'SAMEORIGIN',
'zendesk-rate-limit-tickets-update': 'total=100; remaining=99; resets=60',
'x-rate-limit': '700',
'rate-limit': '700',
'x-rate-limit-remaining': '699',
'rate-limit-remaining': '699',
'rate-limit-reset': '60',
'strict-transport-security': 'max-age=31536000;',
'cache-control': 'no-cache',
'x-zendesk-origin-server': 'classic-app-server-5b7bb5f96b-2bngr',
'set-cookie': [Array],
'x-request-id': '792c83f6384a5f9a-SMF, 792c83f6384a5f9a-SMF',
'x-runtime': '0.086818',
'x-zendesk-zorg': 'yes',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=mwQlS2H5vr2L4HJeTbyCvhjJbRJIwwhO%2FjJFw1z5cpIkak9Oke5GtqcaWsrzIF9gnYxTnkiPAFpkBgprHoXcr2yi%2FvA7grLEoQvXeHhsSmzOnu2LslqRDbzYeeMhRRtQwIrE0uLhrZJxTzlo%2FIfcKZ4%3D"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}',
server: 'cloudflare',
'cf-ray': '792c83f6384a5f9a-SMF'
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 10000,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
baseURL: 'https://***.zendesk.com/',
method: 'put',
url: '/api/v2/tickets/69519.json',
data: '{"ticket":{"status":"open","comment":{"html_body":"Follow-up Notes: \\n<p><br></p>","public":false}}}'
},
If you will notice, the 'url' and 'data' properties of the config object in my case proved I was hitting the correct api endpoint and I was also providing the correctly formatted payload. This led me to pull the tickets status and confirm it was closed, which was the source reason for the 422 response.

Resources