Image thumbnails for a LiveBroadcast object - youtube

I can't seem to associate image thumbnails with a LiveBroadcast object as per the documentation when trying to create a live stream via the API.
For my application, I am using the following reference:
https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#snippet.thumbnails
Here's an example of my payload sent to /liveBroadcasts:
array:3 [
"snippet" => array:5 [
"title" => "Test broadcast"
"description" => "Test description",
"thumbnails" => array:1 [
"default" => array:3 [
"url" => "my-image"
"width" => 120
"height" => 90
]
]
"scheduledStartTime" => "2021-03-01T21:35:37.000000Z"
"scheduledEndTime" => "2021-03-01T21:40:37.000000Z"
]
"contentDetails" => array:2 [
"enableAutoStart" => true
"enableAutoStop" => true
]
"status" => array:1 [
"privacyStatus" => "public"
]
]
The URL to my-image of course is actually a working URL.
Must the images in thumbnails be previously uploaded to YouTube and hosted there instead? What else could I be missing?
Thank you!

According to the official specs of the LiveBroadcasts.insert and LiveBroadcasts.update API endpoints, you're not allowed to set the respective live broadcast resource object's thumbnails property when invoking either of these endpoints:
Neither the request body of the former endpoint, nor the request body of the latter one has specified the property thumbnails among those accepted to be initialized or, respectively, modified.
For to update your live broadcast's thumbnails, you have to use the Thumbnails.set API endpoint instead, invoked appropriately with its request parameter videoId set to the ID of your broadcast.
For PHP (though it's not clear from your post what's your programming language/environment), look for the official Google sample code that is uploading thumbnails to YouTube using Thumbnails.set: upload_thumbnail.php.

Related

How do I iterate over this JSON object?

This is an object that is returned as a response in an HTTP POST request:
res.body
=> "{\"id\":\"a3adasfaf3\",\"url\":\"https://someurl/a3adasfaf3\",\"created\":\"2016-05-30T07:00:58Z\",\"modified\":\"2016-05-30T07:00:58Z\",\"files_hash\":\"cljhlk2j3l2kj34hlke18\",\"language\":\"ruby\",\"title\":\"Some weird hello world message\",\"public\":false,\"owner\":\"kljhlk2jh34lk2jh4l2kj3h4l2kj4h23l4kjh2l4k\",\"files\":[{\"name\":\"Some-weird-hello-world-message.rb\",\"content\":\"puts \\\"Some weird hello world message.\\\"\\r\\n\"}]}"
I am trying to pull out, and translate the various attributes of that response. For instance, at the very least the id and url.
How do I do this?
For the record, I am using Ruby's NET/HTTP std lib to send the POST request and get back this response.
Edit 1
For bonus points, all I want is the actual value stored in each attribute (i.e. the actual id (which is just a string) and a url (which is a typical URL). So if you included how I might both access that attribute and then sanitize it at the same time that would be awesome.
Use JSON.parse to parse the response.
response = "{\"id\":\"a3adasfaf3\",\"url\":\"https://someurl/a3adasfaf3\",\"created\":\"2016-05-30T07:00:58Z\",\"modified\":\"2016-05-30T07:00:58Z\",\"files_hash\":\"cljhlk2j3l2kj34hlke18\",\"language\":\"ruby\",\"title\":\"Some weird hello world message\",\"public\":false,\"owner\":\"kljhlk2jh34lk2jh4l2kj3h4l2kj4h23l4kjh2l4k\",\"files\":[{\"name\":\"Some-weird-hello-world-message.rb\",\"content\":\"puts \\\"Some weird hello world message.\\\"\\r\\n\"}]}"
require 'json'
JSON.parse response
# output:
# {"id"=>"a3adasfaf3", "url"=>"https://someurl/a3adasfaf3", "created"=>"2016-05-30T07:00:58Z", "modified"=>"2016-05-30T07:00:58Z", "files_hash"=>"cljhlk2j3l2kj34hlke18", "language"=>"ruby", "title"=>"Some weird hello world message", "public"=>false, "owner"=>"kljhlk2jh34lk2jh4l2kj3h4l2kj4h23l4kjh2l4k", "files"=>[{"name"=>"Some-weird-hello-world-message.rb", "content"=>"puts \"Some weird hello world message.\"\r\n"}]}
response["name"] # => a3adasfaf3
You need to parse it with JSON.parse
Example:
parsed_hash = JSON.parse res.body
Result:
{
"id" => "a3adasfaf3",
"url" => "https://someurl/a3adasfaf3",
"created" => "2016-05-30T07:00:58Z",
"modified" => "2016-05-30T07:00:58Z",
"files_hash" => "cljhlk2j3l2kj34hlke18",
"language" => "ruby",
"title" => "Some weird hello world message",
"public" => false,
"owner" => "kljhlk2jh34lk2jh4l2kj3h4l2kj4h23l4kjh2l4k",
"files" => [
[0] {
"name" => "Some-weird-hello-world-message.rb",
"content" => "puts \"Some weird hello world message.\"\r\n"
}
]
}
To access the id:
parsed_hash['id']
To access the url:
parsed_hash['url']
Want to access it by symbols ?
parsed_hash = JSON.parse(res.body).symbolize_keys
You can now access id and url by parsed_hash[:id] and parsed_hash[:url]

CakePHP 3 routing dynamic url

I have an eCommerce website and need to create some custom URLs. These URLs will be generated dynamically. The structure will be
Example URL: http://website.com/categoryname/product-title
Here the category name is dynamic. It will change for each product, it can be
website.com/buttons/CP1 or
website.com/ribbons/red so on
In any case these URLs should be redirected to http://website.com/products/productdetail/product-title
I tried the following script:
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
['type' => '\b(?:(?!admin)\w)+\b'],
[
'slug' => '[A-Za-z-]+',
'pass' => [
'slug'
]
]
);
['type' => '\b(?:(?!admin)\w)+\b'] is to exclude the other controllers. In this case 'Admin'. This works but the parameters passed through the URL (product-title) is not getting in the controller function(productDetail)
Any help will be appreciated.
It is fixed. Updated script below.
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
[
'type' => '\b(?:(?!admin)\w)+\b',
'pass' => ['slug']
]);
According to the API the connect() function only accepts 3 parameters and you are actually passing 4. See Cake Routing Router - Connect
I have not tested this at all, but I think you should re-write it like this:
$routes->connect(
'/:type/:slug/*',
['controller' => 'Products','action' => 'productDetail'],
[
'type' => '\b(?:(?!admin)\w)+\b',
'slug' => '[A-Za-z-]+',
'pass' => ['slug']
]
);

Unable to retrieve video metrics using Youtube Analytics API

According to the Youtube Analytics API documentation (https://developers.google.com/youtube/analytics/v1/available_reports), it looks like you should be able to retrieve metrics for specific videos using the "video" dimension. I am able to get all other metrics successfully - either specifying dimensions like "day" and "country" or supplying no dimension at all.
But when I change the dimensions value to "video", I get a 400 error code with the message "The query is not supported. Check the documentation for supported queries." This is a channel report - not a content owner report - but according to the documentation, this should be a valid report request. I've even tried limiting the result set with a number of extra parameters like start-index, max-results, and sort.
WORKS
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "day"})
DOES NOT WORK - returns 400 error
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video",
"start-index" => 1,
"max-results" => 5,
"sort" => "views"})
Has anyone been able to make a successful request for a channel report for video level details?
So the following does work:
channel==USER_ID
start-date=YYYY-MM-DD
end-date=YYYY-MM-DD
metrics=views
dimensions=video
max-results=10
sort=-views
The important thing is that you need to sort by descending views if you want to run a dimensions=video report, and you can only retrieve at most 10 results. This is explained in the second table at
https://developers.google.com/youtube/analytics/v1/available_reports#Channel_Reports
The 10 max results mentioned in their docs, ordered by decreasing views, is obviously an artificial limit imposed by the backend source for Analytics data, but that's all the API could support before. Google just updated it so you can get up to 200 video results - https://developers.google.com/youtube/analytics/revision_history
If you're in a scenario where you want to get Analytics data for arbitrary videos in a given account, not just the 10 with the most views, you need to set the dimension to something other than video, and then run a report with a filter= set to each video id in your account that you're interested in. Again, this might change in the future, but as of right now the Analytics API isn't suited for getting a huge dump of data for every single video in an account in a single API call.
Note that a recent change, in Aug 2014, to YouTube API now allows fetching metrics for up to 200 videos per API call.
See https://developers.google.com/youtube/analytics/revision_history for Aug 28, 2014

youtube-g and rails3

I am new to using youtube-g gem and i would like to embed a youtube video rapper that plays videos on my rails app hosted from youtube. pls does anyone know a youtube-g tutorial or another gem with a simpler readme and documentation that can help. So also a quick tutorial help as an answer would be great
The 'youtube-g' gem was actually replaced by the 'youtube_it' gem located here: https://github.com/kylejginavan/youtube_it
If all you want to do is a regular embed of a youtube video, you can just use this wrapper (HAML syntax):
%iframe{:title => "YouTube video player", :class => "youtube-player", :type => "text/html", :width => "425", :height => "349",:src => #your_model_name.video_link, :frameborder => "0", :allowFullScreen => true, :id => 'my_video_player' }
If you want to dynamically pull videos from your youTube channel you need to create a client and pull the stream like so:
client = YouTubeIt::Client.new( :username => 'your_user_name', :password => 'you_password', :dev_key => 'your_api_key')
results = client.videos_by(:user => 'your_user_display_name')
That will give you a VideoSearch Object. If you wanted to iterate through all of those video objects:
results.videos
That will return an array of Video objects where you have access to all of these attributes listed here: http://rubydoc.info/gems/youtube_it/1.4.1/YouTubeIt/Model/Video
This includes the YouTube url. If you wanted to use the player and and url on your page, you can just do some regEx to extract the video_id and build it yourself. Hope this helps.

Docmail API for ROR application for postcard

I am using docmail's Simple API for sending Postcard.They have implemented this functionality recently, but I didn't get any sample code or instruction for implementation.
Thanks in advance,
Gaurav Soni
I got my answer.Here is a sample code that can interact with Docmail Simple API methods.
require "base64"
require "soap/wsdlDriver"
class TestDocmailLetterSending
def initialize(account)
api="https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?wsdl"
#test = SOAP::WSDLDriverFactory.new(api).create_rpc_driver
contents = open(file, "rb") do |f|
f.read
end
result = #test.sendLetterToSingleAddress(
'sUsr' => "username",
'sPwd' => "password",
'sMailingName' => "string",
'sCallingApplicationID' => "string",
'bColour' => true,
'bDuplex' => true or false,
'eDeliveryType' => "StandardClass",
'sTemplateFileName' => File.basename(file),
'eAddressNameFormat' => "FullName",
'bTemplateData' => contents,
'sFirstName' => first_name,
'sLastName' => last_name,
'sAddress1' => "",
'sAddress2' => ,
'sAddress3' => ,
'sAddress4' => ,
'sPostCode' => ,
'bProofApprovalRequired' => 'false'
)
end
end
We don't have any RoR examples at this time - others here may be able to help, but it's essentially a SOAP webservice, with the SimpleAPI using less complex data types than the standard version. The standard API already lets you send postcards and letters, but is more complex to use from some environments due to it's complex data types.
The test version of Docmail's SimpleAPI has now been updated to expose postcard calls to allow physical postcards to be send via the Simple version of the API. Once we're happy with the updates, we'll make them available in the live version too.
Although you've probably already been through the other info on the API, here are some links/addresses in case anyone else needs them:
Docmail API Info Page
Simple API Test Webservice & Website (for the Simple API Live versions, replace "Test" with "Live"):
https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?WSDL
https://www.cfhdocmail.com/Test
Hope that helps.
Will
(from Docmail)

Resources