YouTube Content ID API insert asset returns 403 - youtube-api

I am able to get and list assets using googleapiclient and oauth2client,
but when I try to add one, I get 403:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/youtube/partner/v1/assets?alt=json returned "Forbidden". Details: "[{'message': 'Forbidden', 'domain': 'global', 'reason': 'forbidden'}]">
Edit:
here's the piece of code that does the insertion:
def insert_asset(self, work_id=None, artist=None, title=None, isrc=None):
body = {
"kind": "youtubePartner#asset",
"type": "sound_recording",
"status": "active",
"metadataMine": {
"customId": work_id,
"title": title,
"isrc": isrc,
"artist": [artist],
},
}
return self.service_youtube_content_id.assets().insert(body=body).execute()
and the service_youtube_content_id is instantiated as
self.service_youtube_content_id = build(
"youtubePartner", "v1", http=self.http, static_discovery=False
)

Related

Serilog expression to exclude http 200 and http 302?

I'm using serilog and it's nicely logging http requests to my asp.net core web application.
However I want to filter out the noise of http 200 and http 302 (basically only interested in 5xx and 4xx).
I've tried a lot of variations on the following:
... snip ...
"Using": [ "Serilog.Expressions" ],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "#l = 'Information' and Properties.StatusCode in ['200', '302']"
}
}
],
... snip ...
But to no success.
The LogEvent properties looks like (:
{
"TimeStamp": "2021-12-09T09:00:18.1586954",
"Level": "Information",
"Message": "HTTP \"GET\" \"/xxx/yyy\" responded 200 in 50.2048 ms",
"MessageTemplate": "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms",
"Properties": {
"RequestMethod": "GET",
"RequestPath": "/xxx/yyy",
"StatusCode": 200,
"Elapsed": 50.2048,
"SourceContext": "Serilog.AspNetCore.RequestLoggingMiddleware",
"RequestId": "8000050f-0006-eb00-b63f-84710c7967bb"
},
"Renderings": {
"Elapsed": [
{
"Format": "0.0000",
"Rendering": "50.2048"
}
]
}
}
Serilog is paying attention if I use a filter like "#l = 'Information'", but any attempt to filter based upon LogEvent properties does not work.
Any help would be appreciated!
Serilog.Expressions doesn't require dotting through a Properties subobject: all of the event's properties are top-level names.
StatusCode is also a number, not a string, so you don't need quotes within the array of status code values to exclude.
Your expression should look like:
#l = 'Information' and StatusCode in [200, 302]

Can't Delete Youtube Subscription With API

I have the code setup for the Youtube API with oauth login. Login appears to work properly. I can even see the requests hitting my analytics. However, when I run the code to unsubscribe from a channel, it never works on any channel ID I give it. It should be noted that I'm using the exact example from googles dev docs(see "full sample" option for javascript)... I'm guessing the code is correct and this is some other auth/lookup problem.
API code:
alert("deleting steven!!!!!!");
buildApiRequest('DELETE',
'/youtube/v3/subscriptions',
{'id': 'UCMtFAi84ehTSYSE9XoHefig'});
Stock Youtube API Code:
function executeRequest(request) {
request.execute(function(response) {
console.log(response);
});
}
function buildApiRequest(requestMethod, path, params, properties) {
params = removeEmptyParams(params);
var request;
if (properties) {
var resource = createResource(properties);
request = gapi.client.request({
'body': resource,
'method': requestMethod,
'path': path,
'params': params
});
} else {
request = gapi.client.request({
'method': requestMethod,
'path': path,
'params': params
});
}
executeRequest(request);
}
Here is the error:
{
"error": {
"errors": [
{
"domain": "youtube.subscription",
"reason": "subscriptionNotFound",
"message": "The subscription that you are trying to delete cannot be found. Check the value of the requests \u003ccode\u003eid\u003c/code\u003e parameter to ensure that it is correct."
}
],
"code": 404,
"message": "The subscription that you are trying to delete cannot be found. Check the value of the requests \u003ccode\u003eid\u003c/code\u003e parameter to ensure that it is correct."
}
}
Remember that the ID you have to send is not the channel ID. It's the ID of the subscriptions.
You can get it by sending request to check your subscriptions with the channel. For example
Request:
buildApiRequest('GET',
'/youtube/v3/subscriptions',
{'forChannelId': 'UCEhZglE9MQ4zTL5ErNXt5mg',
'mine': 'true',
'part': 'snippet,contentDetails'});
Response:
{
"kind": "youtube#subscription",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/KrR9MNb4Xs1eNjWMxAH-f5ccsos\"",
"id": "Xmg72z6q83hK2hjx0J4ZwNVcgGz8fu9JCjeHu6eIb3M",
"snippet": {
"publishedAt": "2018-09-30T16:51:47.000Z",
"title": "Rebeca Willett",
"description": "",
"resourceId": {
"kind": "youtube#channel",
"channelId": "UCEhZglE9MQ4zTL5ErNXt5mg"
},
"channelId": "UCWfZYaoFrUOSoHNhCOOqKCQ",
"thumbnails": {
...
}
Using ID in the response to send request for unsubscribing:
buildApiRequest('DELETE',
'/youtube/v3/subscriptions',
{'id': 'Xmg72z6q83hK2hjx0J4ZwNVcgGz8fu9JCjeHu6eIb3M'});
Here is the google docs for getting subscriptions ID

Cannot create a VSTS webhook subscription for punlisherId = tfs and eventId tfvc.checkin via the REST API

I am trying to create a VSTS webhook subscription for publisherId= tfs and eventType= tfvc.checkin. Here's the sample Post request :
Url : https://testvstsaccount.visualstudio.com/_apis/hooks/subscriptions?api-version=1.0
Request Body :
{
"publisherId": "tfs",
"eventType": "tfvc.checkin",
"resourceVersion": "1.0-preview.1",
"consumerId": "webHooks",
"consumerActionId": "httpRequest",
"publisherInputs": {
"path": "$/"
},
"consumerInputs": {
"url": "https://myservice/myhookeventreceiver"
}
}
I am getting 400 Bad Request in response.
Response body :
{
"$id": "1",
"innerException": null,
"message": "Subscription input 'path' is not supported at scope 'collection'.",
"typeName": "Microsoft.VisualStudio.Services.ServiceHooks.WebApi.SubscriptionInputException, Microsoft.VisualStudio.Services.ServiceHooks.WebApi, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"typeKey": "SubscriptionInputException",
"errorCode": 0,
"eventId": 4501
}
Can someone please help me understand the correct way to create this webhook.
The path is filtering to checkins that change one or more files under the specified path. It should look like $/TeamProject, or $/TeamProject/Project, or $/TeamProject/Project/.... $/ is not supported. Check my example below:
POST https://xxx.visualstudio.com/DefaultCollection/_apis/hooks/subscriptions?api-version=1.0
Content-Type: application/json
{
"consumerActionId": "httpRequest",
"consumerId": "webHooks",
"consumerInputs": { "url": "https://xxx.visualstudio.com" },
"eventType": "tfvc.checkin",
"publisherId": "tfs",
"publisherInputs": {
"path": "$/TestCase/TestCaseProject",
"projectId": "1decf66b-1974-43e3-xxxx-ba9a3fd2xxxx"
},
"resourceVersion": "1.0",
"scope": 1
}

Youtube API: Comment Insert 403 forbidden insufficient permissions

I'm using the API explorer at the bottom of https://developers.google.com/youtube/v3/docs/commentThreads/insert to test this call. I am requesting the scope https://www.googleapis.com/auth/youtube.force-ssl. Appreciate any help!
REQUEST:
POST https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&fields=id&key={YOUR_API_KEY}
{
"snippet": {
"topLevelComment": {
"snippet": {
"textOriginal": "comment from gdev"
}
},
"videoId": "B5BypNLbBgQ",
"channelId": "UCNqqFgLtbSjc9Er7XFv4wbA"
}
}
RESPONSE:
{
"error": {
"errors": [
{
"domain": "youtube.commentThread",
"reason": "forbidden",
"message": "The comment thread could not be created due to insufficient permissions. The request might not be properly authorized.",
"locationType": "other",
"location": "body"
}
],
"code": 403,
"message": "The comment thread could not be created due to insufficient permissions. The request might not be properly authorized."
}
}
The video was private.... Worked fine on a public video.
I had a similar problem. I needed to set the token in the header. the request body needs to have:
part: "snippet"
I think you also would need to set a header of:
Authorization: 'Bearer ' + access_token
I uploaded a video and by default the comments were disabled. Once I changed to "Allow all comments" I could post via the API.

branding settings error youtube api

I have to update the featured video of my channel using youtube api.
When I sent PUT request using api explorer of the form
PUT https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&key={YOUR_API_KEY}
{
"brandingSettings": {
"channel": {
"featuredChannelsTitle": "featured channel",
"featuredChannelsUrls": [
"http://www.youtube.com/user/channelname"
]
}
},
"id": "channelId"
}
I am getting response as follows
404 Not Found
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.channel",
"reason": "channelNotFound",
"message": "Channel branding options not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Channel branding options not found."
}
}
Please let me know where I am going wrong.
I was giving the wrong channel ID. But now I am trying with the correct Channel Id, and I am getting yet another error message.
Content-Type: application/json
Authorization: Bearer ya29.1.AADtN_X2UP_3BfFvUwAkvLp0d0mk1U-itJNVtWMPEJQU8G7INQ5q-UpI1yNMYniiLQ
X-JavaScript-User-Agent: Google APIs Explorer
{
"id": channelId,
"brandingSettings": {
"channel": {
"featuredChannelsUrls": [
" http://www.youtube.com/user/USERNAME"
],
"featuredChannelsTitle": "Featured Channels"
}
}
}
Response is 400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.channel",
"reason": "brandingValidationError",
"message": "Channel branding validation failed.",
"locationType": "parameter",
"location": "brandingSettings"
}
],
"code": 400,
"message": "Channel branding validation failed."
}
}
If you can provide me a sample request it would be really helpful
As it says in the error message, it couldn't find the channel, make sure you are giving the right channel id.
The way to do it in API, do a channels->list request and use that response object, modify it and put it back. (Most important make sure the id is there and set.)

Resources