I'm using Google's Apps Script for this project. I'm using the YouTube data API V3 and of that API I am using the PlaylistItems class. I'm trying to insert a video into a playlist and I've pieced together what I can from the documentation that they have given.
YouTube.PlaylistItems.insert({
"part": [
"snippet"
],
"resource": {
"snippet": {
"playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": testVidId
// testVidId is the ID of the video I'm trying to insert
}
}
}
});
When I run this though, I get an error of
Exception: Invalid number of arguments provided. Expected 2-3 only
My question is: what argument am I missing?
I believe your goal as follows.
You want to insert an item to the play list using Google Apps Script.
Modification point:
When YouTube.PlaylistItems.insert(resource, part) is used, the arguments are resource, part which are an object and an array of string, respectively.
When your script is modified, it becomes as follows.
Modified script:
YouTube.PlaylistItems.insert(
{
"snippet": {
"playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": testVidId
}
}
},
["snippet"]
);
Note:
Before you use this, please confirm whether YouTube Data API v3 is enabled at Advanced Google services, again.
Reference:
PlaylistItems: insert
Related
I'm trying to figure out if a YouTube video is embeddable using the YouTube Data API v3, from answers to similar questions I noticed the status.embeddable property of videos, for a request like this:
https://www.googleapis.com/youtube/v3/videos?id=63flkf3S1bE&part=contentDetails,status&key={MY_API_KEY}
The response is the following
{
"kind": "youtube#videoListResponse",
"etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/ctZQYtBcOuMdnQXh8-Fv1EbS_VA\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/Cd8aGZD09NPuGYNumIEozZs2S90\"",
"id": "63flkf3S1bE",
"contentDetails": {
"duration": "PT8M23S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"projection": "rectangular"
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
}
}
]
}
The embeddable parameter under status is returned as true, HOWEVER this video is not actually embeddable, as can be seen here.
When actually embedding the video using the iframe API, there is a more detailed error message as well:
Video unavailable
This video contains content from International Olympic Committee, who has blocked it from display on this website or application.
Watch on YouTube
I don't see how it is possible to detect this case from the YouTube Data API - can anyone help out?
Other option is used in this answer:
Here, you can use the following URL:
https://www.youtube.com/get_video_info?video_id=<VIDEO_ID>
Where VIDEO_ID is the YouTube video_id you want retrieve the information.
In this case, once you get the response, you'll see a property called "playabilityStatus.status".
Here is a extract of the response:
"playabilityStatus": {
"status": "UNPLAYABLE",
"reason": "The video is not available",
"errorScreen": {
"playerErrorMessageRenderer": {
"reason": {
"simpleText": "The video is not available"
},
Additional to johnh10's answer, some of the results saw in the YouTube webpage is not always shown/available in the APIs.
I have the answer. The file that outputs from the https://www.youtube.com/get_video_info?video_id=
is nothing more than a standard text file that is URLENCODED.
To see it properly you first have to DECODE it using a URLDECODER and then you have to separate the json part from the URL querystring part. To take a look at the JSON part you can use a json formatted and to look at the URL part you can use PrettyPrint URL.
Once you do this you will notice that the tag you are looking for to validate weather the video is playable or not is the one mentioned by the other user here. It sits on the URL parameter named "player_response", after you DECODE the file you will find it easily. This parameter holds a longer JSON file that has the playability status under playabilityStatus.Status.
To manipulate it on Javascript simply parse this part of the file as a JSON file and access your node of choice, or parse it as a text and search for the playabilityStatus node that must be unencoded if you dont care to decode it (nothing to fear, only some %2D and %7B instead of spaces and curly brackets).
Good luck!
Unfortunately, this 'copyright check' happens directly from the player. This data is not available through the API.
I'm implementing GA Enhanced E-commerce using the new gtag.js library. I want to send information about product impressions and product clicks, following the documentation here: https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce.
Everything works (I can see the data in GA), except for Product List Name.
The docs seem to be inconsistent in naming the property (sometimes it's called "list" and sometimes "list_name") and none of them worked for me.
Here's my (simplified) code:
deals = [
{
"id": "18",
"name": "Some product",
"list": "All Deals", // also tried "list_name" here
"category": "Multiplatform",
"list_position": "1",
"price": "18,39",
"currency": "EUR",
"product_url": "https://www.amazon.com/someproduct",
},
...
]
...
// on page load
gtag('event', 'view_item_list', {
"items": deals
});
...
// on click
gtag('event', 'select_content', {
"content_type": "product",
"items": [
deals[0]
]
});
All the data successfully make their way to GA, but Product List Name shows (not set), no matter what:
Thanks for any idea on how to fix/debug this!
there is an error/mistake/inconsistency in gtag documentation:
you should use list_name instead of list
it works as expected with list_name
!!! DO NOT USE gtag as it does not send list_name value with events such as select_content and view_item
in short, query parameter pal (Product Action List) for collect call via gtag is not included, when using gtag — this is a major error comparing to analytics.js implementation.
You can send 2 events, when adding to cart from any list:
gtag('event','view_item',deals); gtag('event','add_to_cart',deals);
name of list must be set in list_name.
deals = [{"id": "18","name": "Some product","list_name": "All Deals", ...}]
Then it works fine.
I am trying to use this dataset to determine which district boundary an address (passed into the API call) falls within.
The endpoint returns an array of objects for each district or council. The polygon is found within the "the_geom" property, with 2 properties - type and coordinates. I have tried using $where, but I get errors.
[
{
"comments": "Inaugurated 2015-06-22",
"council": "1",
"councilper": "Scott Griggs",
"district": "1",
"objectid": "1",
"shape_area": "343352603.892",
"shape_leng": "88541.3042539",
"the_geom": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-96.80995700065864,
32.77138899977414
],
[
-96.80969800043205,
32.77121999997131
],
[ ...
I tried to use the query below, but it gave me an error:
https://www.dallasopendata.com/resource/h9ws-fqcn.json?$where=within_polygon(the_geom, 'MULTIPOLYGON (((-96.800270, 32.779091)))')
This is the page reference page - https://www.dallasopendata.com/Geography-Boundaries/Adopted-Council-Districts/6dcw-hhpj
And this is the endpoint- https://www.dallasopendata.com/resource/dgxr-hmze.json
any help would be greatly appreciated.
I suspect you're the developer who popped into our IRC channel, but I'll answer here too!
You're pretty close here! What you want to do here is use the intersects(...) SoQL function with a Well Known Text (WKT) POINT.
Here's an example that works for your use case:
https://www.dallasopendata.com/resource/h9ws-fqcn.json?$where=intersects(the_geom,%20%27POINT%20(-96.7994007%2032.775765)%27)
We have a working PHP function that grabs specific YouTube video information using YouTube API v3.
We're trying to use JavaScript (jQuery) to do the same thing. The issue is that using our PHP function causes the page to load very slowly while it's retrieving the data. We're hoping that using JavaScript will allow our page to load before (or during) the data requests from YouTube.
First of all, this is an example url for one of our videos (you will need an API key to see the returned information yourself):
https://www.googleapis.com/youtube/v3/videos?part=statistics&id=ce5KbCTfHoA&key={YOUR_API_KEY}
That specific url will return this information:
{
"kind": "youtube#videoListResponse",
"etag": "\"jOXstHOM20qemPbHbyzf7ztZ7rI/qRFx1vTFF-k7dkRzNB5rGQ-dqiQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"jOXstHOM20qemPbHbyzf7ztZ7rI/2yn7rCfXCu0o-GNVtMEQqYssSpE\"",
"id": "ce5KbCTfHoA",
"statistics": {
"viewCount": "33169",
"likeCount": "281",
"dislikeCount": "3",
"favoriteCount": "0",
"commentCount": "85"
}
}
]
}
We are trying to retrieve the likeCount and dislikeCount of this video using JavaScript.
We can achieve this using PHP in the following manner:
function getVideoRatings() {
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id={VIDEO_ID}&key={YOUR_API_KEY}");
$json_data = json_decode($JSON, true);
$likes = $json_data['items'][0]['statistics']['likeCount'];
$dislikes = $json_data['items'][0]['statistics']['dislikeCount'];
/* some other code... */
}
This successfully parses the json information returned by google and returns the likes (likeCount) and dislikes (dislikeCount) for the video.
We'd like to do this using JavaScript (jQuery). Can anyone please help me figure this out?
I really appreciate any help or bump in the right direction.
Thanks
$.getJSON("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=ce5KbCTfHoA&key={YOUR_API_KEY}", function( data ) {
var likes = data['items'][0]['statistics']['likeCount'];
});
This should work. Use jQuery documentation.
I am using Solr 4 for searching in a java web application.Solr produces a JSON response from which i have to extract search results and translate them into html so user can read that.
I know one solution but it seems dumb an I think there must be intelligent ideas.
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"fl": "id,title",
"indent": "true",
"q": "solr",
"wt": "json"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "1",
"title": "Solr cookbook"
},
{
"id": "2",
"title": "Solr results"
},
{
"id": "3",
"title": "Solr perfect search"
}
]
}
}
After that i eval this text as:
var obj = eval ("(" + txt + ")");
To generate html page i can use either
<script>
document.getElementById("id").innerHTML = obj.response.docs[1].id
document.getElementById("title").innerHTML = obj.response.docs[1].title
</script>
or
document.write(obj.response.docs[1].id);
But limitation is that every time solr gives response with different object structure i.e. an object may have age feild but other can not have because it depends on query.
I want to use a sigle JSP page to display search results(like Google)
for all search queries
is it possible to write a single code segment which works for any possible search results with different schema.
Javascript stops working after encountering any error which is likely in my case. that's also problem.if I use for loop to traverse the object hierarchy it is highly error -prone.
Is it possible with a single view page Thanks.
You might want to consider using ajax-solr - A JavaScript framework for creating user interfaces to Solr
I suggest using Velocity templating which is readily supported in Solr - instead of extracting data from the JSON and rendering the HTML via JS.
Docs here