Php: how to get video urls in my vimeo account - vimeo

I have a vimeo api keys and i uploaded videos this url https://vimeo.com and get my all videos link from this link https://vimeo.com/home/myvideos. Now i got response for all my video links details.
<?php
$urls = array();
$videos = array();
// vimeo test
$urls[] = 'https://vimeo.com/243625359';
$urls[] = 'https://vimeo.com/243438242';
foreach ($urls as $url) {
$videos[] = getVideoDetails($url);
}
function getVideoDetails($url)
{
$host = explode('.', str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))));
$host = isset($host[0]) ? $host[0] : $host;
switch ($host) {
case 'vimeo':
$video_id = substr(parse_url($url, PHP_URL_PATH), 1);
$hash = json_decode(file_get_contents("http://vimeo.com/api/v2/video/{$video_id}.json"));
// header("Content-Type: text/plain");
// print_r($hash);
// exit;
return array(
'provider' => 'Vimeo',
'title' => $hash[0]->title,
'description' => str_replace(array("<br>", "<br/>", "<br />"), NULL, $hash[0]->description),
'description_nl2br' => str_replace(array("\n", "\r", "\r\n", "\n\r"), NULL, $hash[0]->description),
'thumbnail' => $hash[0]->thumbnail_large,
'video' => "https://vimeo.com/" . $hash[0]->id,
'embed_video' => "https://player.vimeo.com/video/" . $hash[0]->id,
);
break;
}
}
header("Content-Type: text/plain");
print_r($videos);
Response:
Array
(
[0] => Array
(
[provider] => Vimeo
[title] => SampleVideo_1280x720_10mb
[description] => Vimeo was born in 2004, created by a group of
filmmakers who wanted an easy and beautiful way to share videos with
their friends. Word started to spread, and an insanely supportive
community of creators began to blossom. Now Vimeo is home to more
than:
[description_nl2br] => Vimeo was born in 2004, created by a group of
filmmakers who wanted an easy and beautiful way to share videos
with their friends. Word started to spread, and an insanely
supportive community of creators began to blossom. Now Vimeo is home
to more than:
[thumbnail] => http://i.vimeocdn.com/video/667808655_640.jpg
[video] => https://vimeo.com/243625359
[embed_video] => https://player.vimeo.com/video/243625359
)
[1] => Array
(
[provider] => Vimeo
[title] => SampleVideo_1280x720_5mb
[description] => We spend our days building a product we love for a growing community of millions. And eating lots of free snacks.
[description_nl2br] => We spend our days building a product we love for a growing community of millions. And eating lots of free snacks.
[thumbnail] => http://i.vimeocdn.com/video/667575091_640.jpg
[video] => https://vimeo.com/243438242
[embed_video] => https://player.vimeo.com/video/243438242
)
)
It's good. I applied my video links manually, but correct way to apply my video links dynamic. I want to get my vimeo video urls in based api keys.

It appears you're using the old Simple API (with this url format: http://vimeo.com/api/v2/video/{$video_id}.json) which is no longer supported by Vimeo.
That said, if your videos are embeddable, you'll likely be better off using oEmbed to get the specified metadata (provider, title, description, thumbnail, video). Vimeo's oEmbed documentation is found here: https://developer.vimeo.com/apis/oembed
Regarding the video and embed_video values you're generating, it's best practice to get the video link and embed code exactly from the API. Because you're generating these values on your own, any changes we make to the URL structure may break your links. For example, unlisted videos have an additional hash after the numerical video_id that your code does not account for.
I hope this information helps!

Related

Google Drive API Notifications - File Watch not Sending Add Notifications - possible reasons?

I just set up Google Drive API Change Notifications, specifying the folderId of a certain shared folder that I have on My Drives. It sends notifications if I change the folder name, but doesn't send notifications if I add files.
I set up the channel successfully, as upon issuing these PHP commands
$client = new Google_Client();
$client->setApplicationName('Some Name');
$client->setAuthConfig( __DIR__ . '/service_account.json');
$client->setScopes(Google_Service_Drive::DRIVE);
$client->fetchAccessTokenWithAssertion();
$token = $client->getAccessToken();
$service = new Google\Service\Drive($client);
$httpclient = new \GuzzleHttp\Client();
$folderid = $someid;
$body = [
'kind' => "api#channel",
'id' => uniqid(),
'type' => 'web_hook',
'resourceId' => $folderid,
'resourceUri' => 'https://www.googleapis.com/drive/v3/files/'.$folderid,
'address' => 'myendpoint'
];
$apiendpoint = 'https://www.googleapis.com/drive/v3/files/' . $folderid . '/watch';
$result = $httpclient->post($apiendpoint, [
'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer {$token['access_token']}"],
'body' => json_encode($body),
"http_errors" => false]);
I see a successful return, and my channel immediately sends a sync message to my endpoint, where I have this
function myendpoint (WP_REST_Request $request) {
$headers= getallheaders();
write_log('in google drive webhook with headers '.print_r($headers, true));
$body = $request->get_body();
write_log('in google drive webhook with body '.print_r($body, true));
global $wpdb;
return http_response_code(200);
}
Via my logging, I see
[07-Nov-2021 12:52:35 UTC] in google drive webhook with headers Array
(
[Host] => courses-test.com
[User-Agent] => APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
[Content-Length] => 0
[Accept] => */*
[Accept-Encoding] => gzip, deflate, br
[X-Forwarded-For] => 66.102.8.121
[X-Forwarded-Proto] => https
[X-Goog-Channel-Expiration] => Sun, 07 Nov 2021 13:51:26 GMT
[X-Goog-Channel-Id] => 6187cbc82a08e
[X-Goog-Message-Number] => 1
[X-Goog-Resource-Id] => resid
[X-Goog-Resource-State] => sync
[X-Goog-Resource-Uri] => https://www.googleapis.com/drive/v3/files/folderid?acknowledgeAbuse=false&supportsAllDrives=false&supportsTeamDrives=false&alt=json
[X-Original-Host] => mydomain
)
I read here
https://developers.google.com/drive/api/v3/push
where it says
"To indicate success, you can return any of the following status codes: 200, 201, 202, 204, or 102."
and hence I am returning return http_response_code(200);
and also read here
https://developers.google.com/drive/api/v3/reference/files/watch
and I don't see anything obvious going on here.
Here
https://developers.google.com/search/docs/advanced/crawling/apis-user-agent?visit_id=637718909398077288-2640249237&rd=1
there is this remark
"Avoid unnecessary retry requests by ensuring that your application is well-designed and responds promptly to notification messages (within seconds)."
Now, when I first set up the channel, my endpoint returns right away, so that would seem to negate the above point.
Also, after I get channel set up, I also run these lines
$optParams = array(
'pageSize' => 10,
'fields' => 'nextPageToken, files(id, name)'
);
$results = $service->files->listFiles($optParams);
and indeed see a listing of files.
So I truly at a loss. When I go into the folder, whose folderId I specified to set up the watch channel, and add a file, or edit a file, I don't receive any notifications. The folder in question is shared, but as I understand, sharing only becomes an issue when dealing with shared drives, which is not my case.
And I read here,
https://developers.google.com/drive/api/v3/push#understanding-drive-api-notification-events
that watching for files being added should indeed work on a file watch, when the file is a folder, since add is one of the events for a resource, and it applies to Files.
**Update:
Ok, I seem to have things working, but not based on an add event. The only thing I changed, is that instead of using Guzzle to make the POST, as I show above, I use this
$channel->setId(uniqid());
$channel->setAddress($body['address']);
$channel->setType('web_hook');
$test = $service->files->watch($folderid, $channel);
Maybe adding some of those extra params in the $body like kind, resourceId, was messing things up when I was using POST via Guzzle. Or now that I know resourceId is not same as folderid, maybe that threw a flag on google's end so that a limited number of notifications were being sent. In any case, just using id', address and type seems to be the way to go, which I think is in the Google Drive Push docs. Just that in those docs, also mention of adding those other params in the request, like 'resourceId'. I suspect if I redo using Guzzle, but specify correct resourceId, or just leave it out and use id', address and type, that it would work.
So now, I get this sort of header in my endpoint when I add a file:
(
[Host] => courses-test.com
[User-Agent] => APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
[Content-Length] => 0
[Accept] => */*
[Accept-Encoding] => gzip, deflate, br
[X-Forwarded-For] => someip
[X-Forwarded-Proto] => https
[X-Goog-Changed] => children
[X-Goog-Channel-Expiration] => Mon, 08 Nov 2021 09:46:10 GMT
[X-Goog-Channel-Id] => chanid
[X-Goog-Message-Number] => num
[X-Goog-Resource-Id] => someid
[X-Goog-Resource-State] => update
[X-Goog-Resource-Uri] => https://www.googleapis.com/drive/v3/files/folderid?acknowledgeAbuse=false&supportsAllDrives=false&supportsTeamDrives=false&alt=json
[X-Original-Host] => mydomain
)
So I can detect [X-Goog-Changed] as being children and just keep track of my current uploaded files and see what the new file is. Or maybe using the fields query string somehow I can directly get the new file id?
Still seems odd that getting info about a new file is such a pain. Maybe it is easier in Google Cloud API and Google wants more people signing up for Cloud. In fact that add event only seems to apply to Cloud buckets.
In short: When watching a folder with files().watch() it is currently not possible to receive notifications about new files added to this folder
There are several workarounds that you can find along with explanations in answers to similar questions:
Use changes().watch():
https://stackoverflow.com/a/26551651/11599789 and https://stackoverflow.com/a/67787626/11599789
Pass the folderId to the token:
https://stackoverflow.com/a/33896300/11599789
Make copy of all file's metadata and query for changes:
https://stackoverflow.com/a/18151189/11599789
Also: There is a relevant feature request on Google's Issue Tracker.
It has been closed due to inactivity, but it is worth "starring" and commenting on it to increase visibility.

Meta Query Returns Nothing when Too Much Data

I am doing a "find dealer" lookup for a company so that users can put in a zip code and a radius and find all the dealers within that radius.
It seems to work fine until I get a couple thousand zip codes.
I am passing in the array of zip codes to a meta_query and checking that against my custom post type dealer with its key of zip to find all dealers that have a zip code that is contained in the $zip_array.
<?php
// This takes in a zip code and returns all zip codes in a specific radius
// using the zip code api: https://www.zipcodeapi.com/API#radius
$api_root = 'https://www.zipcodeapi.com/rest';
$api_key = $ZIP_CODE_API_KEY;
$zip_radius = isset($_POST['radius']) ? $_POST['radius'] : 25;
$zip_code = $_POST['zip'];
$type = isset($_POST['type']) ? $_POST['type'] : array('architectural','auto','safety-security');
$api_url = $api_root.'/'.$api_key.'/radius.json/'.$zip_code.'/'.$zip_radius.'/miles?minimal';
$curl = curl_init($api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additional info: ' . var_export($info));
}
// Because all zip codes come back as strings, we set up an array to push
// the new zip code integers into
$zip_array = array();
// Decode response for easy looping
$curl_response = json_decode($curl_response);
// var_dump($curl_response);
// Change zip code strings to integers and push into zip_array
foreach ($curl_response as $zipcode) {
foreach ($zipcode as $the_zip) {
array_push($zip_array, intval($the_zip));
}
}
$meta_query_args = array(
'post_type' => 'dealer',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'zip',
'value' => $zip_array,
'compare' => 'IN',
'type' => 'NUMERIC'
)
),
'tax_query' => array(
array(
'taxonomy' => 'types',
'field' => 'slug',
'terms' => $type
)
)
);
$meta_query = new WP_Query( $meta_query_args );
?>
After that, I am just doing the standard loop and HTML and echoing out all the dealer information on the page. The API is returning all the zip codes as it should and everything displays as it should and displays quickly, but I have noticed that when I set the radius to 100 miles, for some zip codes in the north east United States, it returns upwards of 2500 zip codes.
For example, 19804 at 75 miles returns around 1200 zip codes and properly displays 9 dealers. 19804 at 100 miles returns around 2200 zip codes and the display loop hits the else and says no dealers match that data.
100 miles at other zip codes that return only 1000 or so returns the data and displays properly.
Is this simply a case of having to check against too many zip codes or am I way off and it is something completely different?
Found the issue. I checked the WordPress debug.log and saw Query Killed. Googled that issue and found that on WP Engine hosting, they limit queries of a certain size.
So, in the wp-config i added the line define( 'WPE_GOVERNOR', false ); and that took WP Engine's query limit off.

Implementing barcode webcam reader jakobreiter quaggajs in Yii2

I am trying to implement a webcam barcode reader to search in my grid but I don't understand how to implement it.
This is in the jakobreiter documentation but not sure the html markup i need to use to make it work.
echo YiiQuagga::widget([
"id" => 'codereader',
'name' => 'BarcodeForm[number]',
'target' => '#barcodeform-number',
'messages' => '#messages',
]);

Cakephp 3.0 download file

I asked a question before about file uploading. I managed to get it working and my next step is getting the file to be downloaded by a customer the files may be different formats from videos to PDFs.
I did read about media views, but they where cakephp 2.0. I have found that 2.0 seems to cause problems for me at least.
I can upload my files for uploading if it helps.
Nased on the link Alex posted, how would I call this function in my view this is the function based from the cakephp book link
public function downloadFile($id)
{
$file = $this->Attachments->getFile($id);
// a view.
$this->response->file(
$file['files/content'],
['download' => true]
);
return $this->response;
}
To get a link to that function (using the cakephp default routing) you would do this in your view:
echo $this->Html->link('Download File', ['controller' => 'Attachments', 'action' => 'download_file', $id]);
public function download(){
$file_path = WWW_ROOT.'uploads'.DS.'file_name.doc';
$this->response->file($file_path, array(
'download' => true,
'name' => 'file_name.ppt',
));
return $this->response;
}

How to get First Data JSON response object properties?

I am using the VinceG\FirstDataApi in the First Data demo mode account fairly successfully. That is, I send a simulated credit card payment, and I receive a full JSON object, error=0, approved=1, etc.
Within this set is some of the information I want to use to construct the "thank you" page or the "Something went wrong" page:
[arrayResponse:protected] => stdClass Object
(
[transaction_error] => 0
[transaction_approved] => 1
[exact_resp_code] => 00
[exact_message] => Transaction Normal
[bank_resp_code] => 100
[bank_message] => Approved
[sequence_no] => 000008
[cvv2] => I
[retrieval_ref_no] => 4241673
[merchant_name] => MY COMPANY NAME
[merchant_address] => MY COMPANY ADDRESS
[merchant_city] => MY COMPANY CITY
[merchant_province] => MY COMPANY STATE
[merchant_country] => United States
[merchant_postal] => MY COMPANY ZIPCODE
[merchant_url] => https:/my.website.com
I have tried to access the properties within the array:
echo "<pre>";
print_r($firstData->arrayResponse);
...and the output is "Cannot access protected property FirstData::$arrayResponse".
Ok, this looks wierd to me, but the answer is:
echo "<pre>";
print_r($firstData->getarrayResponse());
...Appending the word get in front of the protected property arrayResponse to make getarrayResponse(). Looks like a horrible method invention, but there you have it.