If someone could help me with this it would be a life saver!!
(I'm using PARSE)
Basically what this parse job attempts to do is 1) queries all objects of a class called channel 2) loop through each object in the "Results" array which is returned from the query 3) make a call to a Google API which returns a JSON string 4) parse the JSON and save new instances of an Object called Videos
The problem is i keep getting the errors: Failed with: Uncaught SyntaxError: Unexpected token T in :1 Failed with: Uncaught SyntaxError: Unexpected end of input in :0
Parse.Cloud.job("TestFunction", function(request, status) {
var query = new Parse.Query("Channel");
query.find ({
success: function (results) {
var httpRaw;
for (var i = 0; i < results.length; i++) {
var channel_id = results[i].get("channel_id");
Parse.Cloud.httpRequest({
url: 'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCKy1dAqELo0zrOtPkf0eTMw&maxResults=50&order=viewCount&type=video&key=AIzaSyCLGCJOPU8VVj7daoh5HwXZASnmGoc4ylo',
success: function (httpResponse) {
httpRaw = httpResponse.text;
},
error: function (httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
var json = JSON.parse(httpRaw);
for (var z = 0; z < json.items.length ; z++){
var video = new Parse.Object("Video");
video.set("video_id", json.items[z].id.videoId.toString());
video.set("video_title", json.items[z].snippet.title.toString());
video.set("video_description", json.items[z].snippet.description.toString());
video.set("video_thumbnail", json.items[z].snippet.thumbnails.medium.url.toString());
video.set("date_published", json.items[z].snippet.publishedAt.toString());
var relation = video.relation("parent_channel");
relation.add(results[i]);
video.save();
}
}
},
error: function() {
}
});
});