I am unable to create new asset, getting error 403 - youtube-api

I am trying to enable monetization of a video but I'm getting error 403 and no more additional info
$asset = new \Google_Service_YouTubePartner_Asset();
$metadata = new \Google_Service_YouTubePartner_Metadata();
//if (array_key_exists('title', $data)) $metadata->setTitle($data['title']);
//if (array_key_exists('description', $data)) $metadata->setDescription($data['description']);
$metadata->setTitle('test title');
$metadata->setDescription('test desc');
$asset->setMetadata($metadata);
$asset->setType("web");
// Insert the asset resource. Extract its unique asset ID from the API
// response.
$assetInsertResponse = $this->youtube_partner->assets->insert($asset, ['onBehalfOfContentOwner' => $contentOwnerId]);
and the response is always
{
"error": {
"code": 403,
"message": "Forbidden",
"errors": [
{
"message": "Forbidden",
"domain": "global",
"reason": "forbidden"
}
]
}
}
Everything else seems to be working, i.e I can create policies with
$policy = new \Google_Service_YouTubePartner_Policy();
$policyRule = new \Google_Service_YouTubePartner_PolicyRule();
$policyRule->setAction("monetize");
$policy->setRules(array($policyRule));
$policy->setName('test');
$response = $this->youtube_partner->policies->insert($policy);

Related

CommentThreads.list 403

I'm getting:
{
"error": {
"code": 403,
"message": "The video identified by the \u003ccode\u003e\u003ca href="/youtube/v3/docs/commentThreads/list#videoId"\u003evideoId\u003c/a\u003e\u003c/code\u003e parameter has disabled comments.",
"errors": [
{
"message": "The video identified by the \u003ccode\u003e\u003ca href="/youtube/v3/docs/commentThreads/list#videoId"\u003evideoId\u003c/a\u003e\u003c/code\u003e parameter has disabled comments.",
"domain": "youtube.commentThread",
"reason": "commentsDisabled",
"location": "videoId",
"locationType": "parameter"
}
]
}
}
for
GET https://youtube.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&allThreadsRelatedToChannelId=UC14YzmOgfiBEvEEeCDAtfjg
I could not identify any video on that channel with comment-disabled.
Moreover, I do try similar api call on channels that I know that have some videos with comment-disabled - and this API works perfectly (UCb0igM0fY85iaKarWkcLOAQ) with no errors.
Please advise - what's the logic regarding this error..
Thanks

Is that possible to change streamName after livestream create?

I tried to use livestream.update reset streamName, but it return a error
{ "error": { "errors": [ {
"domain": "youtube.liveStream",
"reason": "liveStreamModificationNotAllowed",
"message": "Modification is not allowed in current state" } ], "code": 403, "message": "Modification is not allowed in current state" } }
Is that possible to update or reset streamName after livestream created?
It's not possible to update the streamName after the object is created. You can create a new liveStream object with the same settings and a new name.

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.

Error: "message": "Login Required" when use Youtube Analytics API

I am working with youtube api. when I hit this url "https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=2015-01-01&end-date=2016-01-31&metrics=likes%2Cdislikes&key={API Key}"
it gives 401
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
but I hited in the explorer "https://developers.google.com/apis-explorer/?"
it working fine.
How do I make the first request work?
In your request you are sending key={your key} for an access token you should be sending access_token={your oauth2 access token}
Note: Key is used for public requests. access token is for authenticated requests.
If someone else using JWT authentication on a Google API stumbles upon this question (eg. when using Service Accounts) then make sure to include auth: <your jwtClient> in your API call, like:
First, get the token:
// Configure JWT auth client
var privatekey = require("./<secret>.json")
var jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
['https://www.googleapis.com/auth/drive']
);
// Authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
return;
} else {
console.log("Google autorization complete");
}
});
Then, call the API (but don't forget the auth:jwtClient part)
drive.files.create({
auth: jwtClient,
resource: {<fileMetadata>},
fields: 'id'
}, function (err, file) {
if (err) {
// Handle error
} else {
// Success is much harder to handle
}
});

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