YouTube Api V3 - Videos.update - Forbidden error - javascript

I'm trying to update video's description using Youtube API, but I'm just getting Forbidden Error.
Videos.insert call is actually working, the authentication is being done on the same way for both (as I show on code). But for Videos.update it just doesn't work.
I'm not trying to do these two operations at once, it's just to explain better the situation and make the code shorter to read.
const Youtube = require('youtube-api');
const request = require('request');
// test variables below
const accessToken = 'ASPODKODASP';
const title = 'test';
const description ='test';
const url = 'https://testvideo.url/sadokdas.mp4';
const youtubeId = 'm_23k21423';
Youtube.authenticate({
type: 'oauth',
access_token: accessToken
});
Youtube.videos.insert({
resource: {
snippet: {
title: title,
description: description
},
status: {
privacyStatus: 'public'
}
},
part: 'snippet, status',
media: {
body: request(url)
}
}); // <- THIS WORKS
Youtube.videos.update({
id: youtubeId,
snippet: {
title: title,
description: description,
categoryId: '22'
},
part: 'snippet'
}, (err, data) => {
if (err) {
console.log('error on updating youtube description');
console.log(err);
return;
}
});
I expected the video description to get updated but instead I'm getting
code: 403,
errors:
[ { domain: 'youtube.video',
reason: 'forbidden',
message: 'Forbidden' } ]

You want to update a video of YouTube using "youtube-api" of Node.js.
You have already been able to insert new video using your script.
In your environment, you have already been able to use YouTube Data API.
In your script, an error occurs at Youtube.videos.update().
If my understanding is correct, how about this modification? In this modification, the request body of Youtube.videos.update() was modified.
Modified script:
From:
Youtube.videos.update({
id: youtubeId,
snippet: {
title: title,
description: description,
categoryId: '22'
},
part: 'snippet'
}, (err, data) => {
To:
Youtube.videos.update({
resource: { // Added
id: youtubeId,
snippet: {
title: title,
description: description,
categoryId: '22'
}
},
part: 'snippet'
}, (err, data) => {
References:
Videos: update
youtube-api
If I misunderstood your question, I apologize.

Related

Add image to notification when using sendToTopic method

I want to use sendToTopic method to send notification to a topic, How can I add image to the notification?
There is no option such as notification.imageUrl
It can be done like this -
const message: TopicMessage = {
topic: reqData.topic,
data: {
abc: reqData.abc
},
notification: {
title: reqData.title,
body: reqData.body,
imageUrl: reqData.imageUrl
}
};
// messageRes is a message ID string.
const messageRes = await admin.messaging().send(message);

How to add permissions to a new API with STRAPI (not from dashboard)

I need to do a new api in order to send an email with sendgrid. I followed the official doc and other examples so I did:
config/plugins
module.exports = ({ env }) => ({
email: {
provider: 'sendgrid',
providerOptions: {
apiKey: env('SENDGRID_API_KEY'),
},
settings: {
defaultFrom: 'juliasedefdjian#strapi.io',
defaultReplyTo: 'juliasedefdjian#strapi.io',
},
},
});
then I did a new folder named email in api folder
api/email/config/routes.json
{
"routes": [
{
"method": "POST",
"path": "/email",
"handler": "email.index",
"config": {
"policies": []
}
}
]
}
finally under api/email/controllers/email.js
const { default: createStrapi } = require('strapi');
module.exports = {
index: async (ctx) => {
//build email with data from ctx.request.body
await createStrapi.plugins['email'].services.email.send({
to: 'email#email.com',
from: 'email#email.com',
replyTo: 'email#email.com',
subject: 'test',
text: 'test',
});
ctx.send('Email sent!');
},
};
The real problem is that /email api returns me a 403 even if I did this from the dashboard:
I have done many APIs with strapi but I have never sent emails with it.
Is there a way to add permissions from the code? I have to say that if I use GET method it works, but I need to do it with a POST method, which doesn't. Did I miss something?

How do I add an analytics label to data messages with the Javascript (or typescript) Firebase Admin SDK?

I want set a label in the message.And I read the official document here and similar question here.
But I can't figure out how to write it in javascript.
my code here:
const message = {
notification: {
title: "myTitle",
body: "myBody"
},
condition: "!('TopicA' in topics)",
AnalyticsLabel : "mylabel" <=== something like this?
};
const response = await admin.messaging().send(message);
Here is the trick...
const message = {
notification: {
title: "myTitle",
body: "myBody"
},
condition: "!('TopicA' in topics)",
fcmOptions: {
analyticsLabel : "MyLabel"
}
};

Getting values from my web chat call in my website using backchannel

I'm trying to integrate the backchannel and getting the values.
https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event
I also tried this. Get URL Referer and Origin header from Microsoft Bot Framework
I also tried deserializing the values still not able to get the data.
how can i get the language values?
here's my sample code:
var userinfo = {
id: 'user-id',
name: 'user name',
locale: 'es'
};
var botConnection = new BotChat.DirectLine({
token: 'mytoken',
user: userinfo,
locale: 'es'
});
BotChat.App({
botConnection : botConnection,
user: userinfo,
bot: { id: 'bot-id', name: 'bot name' },
}, document.getElementById('botDiv'));
botConnection
.postActivity({
from: userinfo,
name: 'ConversationUpdate',
type: 'event',
value: '',
})
.subscribe(function (id) {
console.log('"trigger ConversationUpdate" sent');
});
The purpose of this I want to pass the locale to my bot from my website.
just like in the emulator.
Thanks!
I would recommend adding the locale to the back channel event's channel data. That way on the bot side you can simply access the locale in the incoming activity without having to deserialize any JSON objects when you receive the event. Note, you can also use text or value in place of channelData. See the code snippets below.
BotChat Back Channel Event
// Send back channel event
botConnection.postActivity({
from: userinfo,
name: 'setLocale',
type: 'event',
channelData: "es"
}).subscribe(id => console.log(id));
Bot - C#
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
if (turnContext.Activity.Type == ActivityTypes.Message)
{
...
} else if (turnContext.Activity.Type == "event") {
// Check for `setLocale` events
if (turnContext.Activity.Name == "setLocale") {
await turnContext.SendActivityAsync($"Your locale is set to {turnContext.Activity.ChannelData}");
}
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected");
}
}
Hope this helps!

Youtube API v3 Can't reply or rate on any comment

I am trying to comment and rate a comment via API but the resource is always
canRate: false and canReply: false
I
I've tried through google javascript client and http get request, but nothing seems to be working.
$http.get('https://www.googleapis.com/youtube/v3/commentThreads', {
params: {
key: API_KEY,
part: 'snippet',
textFormat: 'plainText',
videoId: VIDEO_ID,
order: 'relevance'
}
}).success(function(response) {
$scope.comments = response.items;
$log.debug($scope.comments);
//var author = item.snippet.topLevelComment.snippet.authorDisplayName;
//var comment = item.snippet.topLevelComment.snippet.textDisplay;
//var nextToken = results.nextPageToken;
//var totalRep = item.snippet.totalReplyCount;
//var parent = item.snippet.topLevelComment.id;
})
.error(function(error) {
$log.error(error);
})
This is what I'm using, I can list them perfectly (even using v3/comments) but can't reply neither rate a comment, this is what I'm using
gapi.client.load('youtube', 'v3', function () {
$scope.selectedComment.snippet.viewerRating = 'like';
var request = gapi.client.youtube.commentThreads.update({
part: "snippet",
body: $scope.selectedComment
});
request.execute(function(response) {
$log.debug(response);
});
});
At the body part I've also tried this
body: {
id: $scope.selectedCommentId,
'snippet': {
'viewerRating': 'like'
}
}
But I get this error
404 The specified comment thread could not be found. Check the value
of the id property in
the request body to ensure that it is correct
You can replay the comment
POST https://www.googleapis.com/youtube/v3/comments?part=snippet&access_token={YOUR_API_KEY}
body
{
"snippet": {
"parentId": "parentCommentID",
"textOriginal": "yoursComment"
}
}
You can get more info here
https://developers.google.com/youtube/v3/docs/comments/insert#examples

Categories