I am trying to delete a playlist that I have created but keep receiving a 404 error.
I have a global var playlistId to remember the playlistId that I have created.
var playlistId
I create the playlist like so :
function createPlaylist() {
var request = gapi.client.youtube.playlists.insert({
part: 'snippet,status',
resource: {
snippet: {
title: 'hard coded title',
description: 'Hard Coded Description'
},
status: {
privacyStatus: 'private'
}
}
});
request.execute(function(response) {
var result = response.result;
if (result) {
playlistId = result.id;
console.log("created playlist " + playlistId)
}
});
}
Then I delete a playlist like so :
function deletePlaylist() {
var request = gapi.client.youtube.playlistItems.delete({
id: playlistId
}).execute();
}
404 Error that I receive is :
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "playlistItemNotFound",
"message": "Playlist item not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Playlist item not found."
}
}
I am giving the playlistId of the PlayList that I have created yet the playlist can not be deleted.
Can anyone give some guidance?
deletePlaylist appears to be attempting to delete a PlaylistItem (i.e. a video) rather than a Playlist itself. Could you try replacing playlistItems with playlists?
Related
I have a strange issue on a system that creates a youtube playlist, and then fills the playlist with videos from a database table.
The code is Version Controlled by GIT, and have no commits in the code for 3-4 months, and it has worked up to a couple of days back.
Suddenly it can't find the items, and therefore doesn't find the id, of the item that it should find. The system creates a list, then find the latest created playlist (which is the one you just created), and then fills the playlist up normally.
I'm not very good as javascript to be honest, are there any good javascript developers out there that can solve this? The error seems pretty common when googling, but In addition to the youtube api use, I find it hard to figure out the issue. Why it suddenly doesn't result items. (If I run a GET in Postman, ill get the correct playlist, so it should be something in the code that isn't working 100%)
function createPlaylist() {
var client = document.getElementsByName("client")[0].value;
var description = document.getElementsByName("information")[0].value;
return gapi.client.youtube.playlists.insert({
"part": [
"snippet,status"
],
"resource": {
"snippet": {
"title": client,
"description": description,
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "mhmGwTDpPf0"
},
"tags": [
"postural workout"
],
"defaultLanguage": "en"
},
"status": {
"privacyStatus": "public"
}
}
})
.then(function(response) {
return gapi.client.youtube.playlists.list({
"part": [
"id,snippet,contentDetails"
],
"maxResults": 1,
"mine": true
})
.then(function(response) {
console.log("Response", response);
MyVars.latestPlaylistID = response.result.items[0].id;
pID = MyVars.latestPlaylistID
console.log(pID + " is the latest playlist");
var doms = document.getElementsByTagName("tr");
// Get every TR into an array
var array = $('tbody > tr').map(function() {
return $.map($(this).data(), function(v) {
return v;
});
}).get();
//array.reverse();
var array = array.filter(function(element){ return element.length>=11});
videosIdArray = array.reverse();
console.log(pID, videosIdArray, 0);
addVideoToPlayList(pID, videosIdArray, 0);
// setTimeout(addVideoToPlayList(pID, videosIdArray, 0), 5000);
document.getElementById("playlistID").innerHTML = 'https://www.youtube.com/playlist?list=' + pID;
document.getElementById("playlistID").href = 'https://www.youtube.com/playlist?list=' + pID;
},
function(err) { console.error("ListPlaylist error", err); });
},
function(err) { console.error("InsertPlaylist error", err); });
}
This is what happens now:
Error
And as you can see the items array is empty.
I have now solved it!
By breaking down the function into smaller functions it seems to give me the correct result. Why the problem suddenly occured is still uknown, but I'm glad it now works.
This is the final solution if others out there are trying to solve similiar issue.
function createPlaylist() {
var client = document.getElementsByName("client")[0].value;
var description = document.getElementsByName("information")[0].value;
return gapi.client.youtube.playlists.insert({
"part": [
"snippet,status"
],
"resource": {
"snippet": {
"title": client,
"description": description,
"position": 1
},
"status": {
"privacyStatus": "public"
}
}
}).then(function(response) {
console.log("Response", response);
});
}
function addToPlaylist() {
return gapi.client.youtube.playlists.list({
"part": [
"id,snippet,contentDetails"
],
"maxResults": 1,
"mine": true
})
.then(function(response) {
console.log("Response", response);
MyVars.latestPlaylistID = response.result.items[0].id;
pID = MyVars.latestPlaylistID
console.log(pID + " is the latest playlist");
var doms = document.getElementsByTagName("tr");
var array = $('tbody > tr').map(function() {
return $.map($(this).data(), function(v) {
return v;
});
}).get();
var array = array.filter(function(element){ return element.length>=11});
videosIdArray = array.reverse();
console.log(pID, videosIdArray, 0);
addVideoToPlayList(pID, videosIdArray, 0);
},
function(err) { console.error("ListPlaylist error", err); });
}
I'm using the guide from https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.02.html to learn how to load data from a json into a dynamoDB table. I have done step 2, however, when I run my code, only some movie files are successfully put into the table and some are not. For a movie that cannot be added, I receive this error:
Unable to add movie Meet Dave . Error JSON: {
"message": "Requested resource not found",
"code": "ResourceNotFoundException",
"time": "2020-11-30T17:38:59.402Z",
"requestId": "2D23NEFAB33E62C6PEFUFGGNM7VV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 28.791430704572328
}
Every time I delete the db and try re-run my code, different movies are successfully added and unsuccessfully added. My code is identical to the step 2 of the guide on the link above.
var allMovies = JSON.parse(fs.readFileSync("movie_data.json", "utf8"));
allMovies.forEach(function (movie) {
var movie_params = {
TableName: "Movies",
Item: {
year: movie.year,
title: movie.title,
info: movie.info,
},
};
docClient.put(movie_params, function (err, data) {
if (err) {
console.error(
"Unable to add movie",
movie.title,
". Error JSON:",
JSON.stringify(err, null, 2)
);
} else {
console.log("PutItem succeeded:", movie.title);
}
});
});
The movie data is a json file containing a list movies with attributes: title, year and info. Does anyone have any idea why this is not working correctly i.e. not putting all of the data successfully into the db table?.
I am trying to insert document in a collection. The structure of the document looks like this:
[{
"observationNum" : 1231,
"observation_data": [{
"child_id": 1234,
"child_observation_data": [{
"activity_performed": true,
"observation_date": 15062016,
"teacher_id": 6789
}]
}]
}]
To achieve this, I have created 3 models. A Model named child_observation_data containing it's data as shown in the JSON structure above. Another Model named observation_data containing child_id and child_observation_data. I am trying to insert the data in the collection as shown below however the data isn't inserted in the observation_data model and child_observation_data model. What am I doing wrong?
function insertData() {
var childObservationDataModelObject = ChildObservationData.ChildObservationData({"activity_performed": true, "observation_date": "17May2016", "teacher_id":789});
var observationDataModelObject = ObservationData.ObservationData({"child_id" : 21386, "child_observation_data":childObservationDataModelObject});
var activityModelObject = new ActivityModel({"observationNumber" : 123456, "observation_data": observationDataModelObject});
activityModelObject.save(function(err, savedObject) {
if(err) {
console.error("error in saving:", err);
return;
}
if(savedObject != null)
console.log("Data saved ", savedObject);
});
ObservationData.getObservationDataModel()
.findOne({"child_id" : 21386})
.populate('child_observation_data')
.exec(function (err, activity) {
if (err)
console.log("error in finding", err);
console.log('The creator is ', activity);
});
}
The console logs are:
Data saved { observation_data: [ 57eb905265ddc958133ac649 ],
_id: 57eb905265ddc958133ac64a,
observationNumber: 123456,
__v: 0 }
The creator is null
I am working on creating labels using JavaScript Gmail API.
function createLabel(userId, newLabelName, callback) {
var request = gapi.client.gmail.users.labels.create({
'userId': userId,
'label': {'name': newLabelName}
});
request.execute(callback);}
This is the code of Developer API Example
I am able to authenticate and even I'll get the label list but while creating the label I am getting the below error.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid request"
}
],
"code": 400,
"message": "Invalid request"
}
}
But when I am using the Try It example It's working but only difference is it's do the POST request with key={Your auth key} which the example provided won't attach that part to URL.
The data you send should be in the resource-parameter, and labelListVisibility and messageListVisibility are also mandatory fields:
function createLabel(userId, newLabelName, callback) {
gapi.client.gmail.users.labels.create({
userId: userId,
resource: {
name: newLabelName,
labelListVisibility: 'labelShow',
messageListVisibility: 'show'
}
}).execute(callback);
}
I am getting this error while we are uploading image to facebook.And i am given the permissions.
https://graph.facebook.com/me/photos
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
This is my as3
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card'};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");
Please help me.
You have to add an Access Token to Object:
access_token:Facebook.getAuthResponse().accessToken
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card', access_token:Facebook.getAuthResponse().accessToken};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");