How to get video duration from Cloudinary? - php

I have a roadblock here. I want to get the video duration from Cloudinary.
Is there any function I can use to get my desired result?
The Only option I found is using Cloudinary API's resource method. I am using the PHP Cloudinary API in this way:
$api = new \Cloudinary\Api();
$result = $api->resource("public_id",array("resource_type" => video","duration"=>true));
print_r($result);
This function gets most of the info of the video but not the video's duration.
I have also tried with PHP 'getID3' Library but it returns an error that says:
Remote files are not supported - please copy the file locally first
If you guys have any idea how to do this in Cloudinary or in PHP, please Share.
Thanks in advance.

Cloudinary supports returning more extensive information by setting the image_metadata parameter to true.
For example:
$result = $api->resource("public_id",array("resource_type" => "video","image_metadata"=>true));
This will also return the duration of the video.

Related

How to delete cloudinary image via PHP

I have an cloudinary_id stored in DB and want to delete this image from Cloudinary.
According documentation I call desctroy method on uploadApi with id which returns result OK. But as I see the image is still available. Dont understand it.
Tis is the code:
$cloudinary = new Cloudinary($config);
return $cloudinary->uploadApi()->destroy($file_id);
This code returns Cloudinary\Api\ApiResponse #d6b5 result => "ok"
Can somebody tell me please what is wrong with this code?
Cloudinary uses CDN to ensure fast delivery of the media resources. That being said, when deleting a media via API, you may need to pass the optional parameter "invalidation" set to true in order to invalidate that object in their CDN.
Here are their API documentation below:
https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
https://cloudinary.com/documentation/admin_api#delete_resources
You may use either upload API or admin API. Both achieve the same result.
Anthony

get filename from google docs using laravel

My site has a feature where users can upload a link to their google docs file. What I want to do is list all the uploaded links in a place. While doing that I need to show the name of the file that is associated with the link.
I can extract the file id from the link and make sure the link is of google docs. Now I need to find a way to get the filename from that. I tried going through the google developer API for google drive, but it is for uploading/doing anything only on the authorized docs. My issue here is, my users upload the files manually to their docs which I have no control over. All I get is a sharable link and somehow get the name out of it. In addition, a thumbnail will also help.
I have tried doing this, but it throws error
$url = "https://www.googleapis.com/drive/v3/files/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA";
// and
$url = "https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing"
$html= file_get_contents($url);
print_r($html);
A dummy link for anyone willing to help: https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing
Since we are getting the URL to the file, we can do a couple of things -
get the id to the file
get what type of file is that
Before I explain how to do that, it is better to know that there can be 2 possible situations. One the file is a google docs file, the other google drive file. Those both start with different URLs.
$url = explode('/', Str::after(
Str::after($request->url, 'https://docs.google.com/'), 'https://drive.google.com/'
));
I am using 2 Str::after() to remove the unnecessary part from the URL. Then I am using explode to convert the URL into an array.
Since we have excluded the useless part from the URL, we are left with document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing in an array form.
So, if we try to do $url[2], we get the id of the file. Also, "document" is also a good thing to note about. I use those to show proper images. There can be 5 different types of them (4 for google docs and 1 for google drive). Those are - document, spreadsheets, forms, presentation for google docs, and file for google drive. I would recommend everyone store these in the database so that extra calculations are not necessary while displaying it.
Now, to answer the actual part of the question. How to get the name. I have created a new model method to handle that.
public function name()
{
$key = config('app.google_api_key');
$url = "https://www.googleapis.com/drive/v3/files/{$this->file_id}?key={$key}";
$response = Http::get($url)->json();
return $response['name'] ?? 'Private File';
}
Don't forget to add your Google API key in the config file app.php (You need to create one). You can get your API key from Google Developer Console and create a project-specific key. Just to note that this key need not be belonging to the user of the URL.
Also, a thing to note here is that $response returns error code if the file is not set to visible to the public or the file is deleted.

How to get video from Instagram public access API?

I know that this api is working to get images but how about videos?
https://www.instagram.com/username/?__a=1
I was able to get the thumbnail of the video but not the source or the url itself.
When you make above API call it would return code in it. looks something like this: BWhyIhRDBCw
Whenever your media nodes has "is_video": true you can make following call:
https://www.instagram.com/p/{code}/?__a=1
for e.g.,
https://www.instagram.com/p/BWhyIhRDBCw/?__a=1
This would return another json. which will have video_url you are looking for.
sample:
"video_url": "https://scontent-bom1-1.cdninstagram.com/vp/437699b67172f450331fa732f0777b18/5A7FE0A0/t50.2886-16/20138822_486349355081174_1539674401849475072_n.mp4",
This url working in local machine but not on my remote server.
When i try to hit from remote server its returning html content.
To hit this api simply use volly library it will return json then u can parse json as per your need.

Getting a facebook name out of a fb id - file_get_contents() not working

Background:
I am making a facebook app where users post messages like in a forum. For that I save the users facebook id to then present their names. I know it is possible to show the name out of a facebook id by using the Graph API, but I can't make it work.
The code I use is the following:
//$fbId is the facebook id to find out the name for
$facebookUrl = "https://graph.facebook.com/".$fbId;
echo(file_get_contents($facebookUrl));
$str = file_get_contents($facebookUrl);
$result = json_decode($str);
echo($result);
return $result->name;
I researched and tested this for hours, but I feel like I'm getting nowhere. I got an idea of how it works from:
http://www.phpexpertsforum.com/how-to-get-the-facebook-name-with-user-id-using-php-code-t1852.html
Didn't work so I researched further from here:
Get user's name from Facebook Graph API
I dowloaded and currently use the Facebook php SDK, but I don't find the way to use it to get anyone's name other than the current user.
The problem here seems to be the file_get_contents() function that returns a false, meaning that it can't read the file.
I checked out the php documentation. Also, by using the php functions fopen() and file().
//echo(pathinfo($facebookUrl, PATHINFO_EXTENSION)); -> Doesn't give any response!
//echo(file_exists($facebookUrl)); -> No response!
//fopen() doesn't work
//file() doesn't work
//file_get_contents() doesn't work
//tried adding an access token to the $facebookUrl but it doesn't make any difference
Any idea of what could be wrong here? Little guidance would be very helpful. What am I doing wrong? What did I miss?
Seems that your allow_url_fopen directive is set to Off.
Look for it in your php.ini (or create a php file containing <?php phpinfo(); ?> and point to it in your browser) and check if is set to 'On'.

execute some function in some php file on another server(apache) and get the returned value

I want to access some function written in some php file on another server and receive the input, I have access to those server files so that I can change them for proper configuration, I have all the privilleges to do so, can anybody please guide me how can I do it, thank you
$result = file_get_contents("http://some.server/out.php");
and in this out.php
<?php
include 'some.php';
function();
I think you can implement web service or an api, and the output could be in xml or json read the content and use it on your website.
It is just Facebook graph API using URL
https://graph.facebook.com/Pepsi
The above link will fetch information regarding Facebook page of Pepsi.

Categories