how to get the private meta data from vimeo private video - php

Hi i cant able to fetch the private meta data like title, duration,image,etc... from the private access video's in Vimeo. Can any one help me to find a solution for this?
I uploaded one video in my account with private mode. I cant able to fetch the meta data details too.
I am using PHP to fetch the details.

This is very similar to: Get URL/Embed code to private Vimeo videos programatically
Unfortunately the answer there has not been marked as the answer, a necessary step to link the two questions together, so I'll repost it here.
Register an API app on https://developer.vimeo.com/apps
This is necessary for every API app. We need to know who is using our system, and how to contact them if necessary.
Generate an access token.
There is general documentation at https://developer.vimeo.com/api/authentication, but you will likely be using the "single user application" workflow. It's a lofty title for "generate an access token via the UI on your application page, then hard code it into your app". This access token will interact with the API on behalf of the user who registered the application.
Request your video information.
There are many different API calls to get video information. You can find these at https://developer.vimeo.com/api/endpoints. /me/videos will show all of the authenticated users videos, /videos/{video_id} will show a single video.
One extra note, if you are using PHP you should use the official Vimeo PHP library: https://github.com/vimeo/vimeo.php

Visite https://github.com/leandrocfe/PHPVimeoAPI_List_Private_Video
List private videos from Vimeo
Modify config.json info vimeo account;
Access video.php and
add vimeo_video_id get param. Ex:
localhost/vimeo/video.php?id=123123123
<?php
//utf-8
header('Content-Type: text/html; charset=utf-8');
//lib vimeo
use Vimeo\Vimeo;
//métodos de inicialização
$config = require(__DIR__ . '/init.php');
//vimeo video id
#$id = $_GET["id"];
//isset get
if(isset($id)){
// vimeo class send config.json paramns
$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
//get data vimeo video
$me = $lib->request("/me/videos/$id");
//iframe vídeo
$embed = $me["body"]["embed"]["html"];
//edit video size
$default_size = 'width="'.$me["body"]["width"].'" height="'.$me["body"]["height"].'"';
$new_size = 'width="420" height="220"';
$embed = str_replace($default_size, $new_size, $embed);
//autoplay
$embed = str_replace('player_id=0', 'player_id=0&autoplay=1', $embed);
}else{
echo("Not find get id video");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Vimeo Vídeo</title>
</head>
<body>
<div><?php echo $embed ?></div>
<div>
<p><b>Name: </b><?php print_r($me["body"]["name"]); ?></p>
<p><b>Description: </b><?php print_r($me["body"]["description"]); ?></p>
<p><b>Link: </b><?php print_r($me["body"]["link"]); ?></p>
<p><b>Likes: </b><?php print_r($me["body"]["embed"]["buttons"]["like"]); ?></p>
<p><b>Data Created: </b><?php print_r($me["body"]["created_time"]); ?></p>
<p><b>Data Modified: </b><?php print_r($me["body"]["modified_time"]); ?></p>
<p><b>Images: </b>
<?php print_r($me["body"]["pictures"]["uri"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][0]["link"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][1]["link"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][2]["link"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][3]["link"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][4]["link"]); ?> |
<?php print_r($me["body"]["pictures"]["sizes"][5]["link"]); ?>
</p>
</div>
<div><?php //print_r($me); //use for show all options ?></div>
</body>
</html>

Related

Twitter REST API: Possible to Hotlink Twitter Images? Why No Image Display In Firefox?

I am trying to extract images from Twitter REST API and display those images.
Insodoing I have come to a logical impasse with my PHP/HTML code not displaying the images in the browser of my localhost PHP built-in developer server. I prefer Firefox as more secure (private) browser, so I first develop in Firefox.
I thought that the issue of images not displaying was perhaps issue of Twitter not allowing hotlinking to their images, however I just tested this same code (below) in both Chrome and Internet Explorer browsers, and all the images appear fine.
So my [updated] question is: why are these images not appearing in either Firefox or Firefox Developer Edition browsers? Twitter clearly doesn't have an issue with hotlinking to their images that have been extracted via their API as demonstrated by images showing up fine in both Chrome and Internet Explorer browsers.
Who has the answer to this interesting issue?
<!DOCTYPE html>
<html lang="en">
<head>
<?php
// USED TO DEBUG WHY HTTPS WAS NOT WORKING IN THE BEGINNING
// var_dump(stream_get_wrappers());
?>
<?php
// REQUIRE TWITTEROAUTH LIBRARY
require "twitteroauth/autoload.php";
// I HAVE HACKED AROUND WITH THIS, BUT DON'T SEE WHY ABRAHAM IS NECESSARY SINCE THERE IS NO FOLDER NAMED ABRAHAM,
// BUT CODE DOES NOT WORK WITHOUT THIS, SO LEAVE IT IN! :)
use Abraham\TwitterOAuth\TwitterOAuth;
// DECLARE VARIABLES OF KEYS, SECRET, TOKEN, & TOKEN_SECRET
$CONSUMER_KEY = "12345";
$CONSUMER_SECRET = "12345";
$access_token = "12345";
$access_token_secret = "12345"
// DEFINE NEW CONNECTION VARIABLE: I.E. CONNECTION TO TWITTER VIA TWITTEROAUTH
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $access_token, $access_token_secret);
// CREATE MULTIPLE-PARAMETER QUERY AS ARRAY
$query = array(
"q" => "#MickeyMouse",
"count" => "1000",
"include_entities" => "true"
);
// MAKE CONNECTION TO TWITTER, GET METHOD FOR "SEARCH/TWEETS", PASS ARRAY AS QUERY
$result = $connection->get("search/tweets", $query);
// TEST OUTPUT FOR DEBUGGING
//var_dump($result);
// CREATE VARIABLES: NEW EMPTY ARRAYS
$ArrayPhotoURLs = array();
// FOR LOOP,
foreach ($result->statuses as $content) {
// IF EACH TWEET/STATUS HAS MEDIA,
if (isset($content->entities->media)) {
// THEN GET THOSE MEDIA URLS
foreach ($content->entities->media as $media) {
$media_url = $media->media_url; // Or $media->media_url_https for the SSL version.
// AND ASSIGN/APPEND EACH MEDIA URL TO THE ARRAY OF MEDIA URLs
$ArrayPhotoURLs[] = $media_url;
// TEST OUTPUT FOR DEBUGGING
//print(gettype($media_url));
//print_r($media_url);
//var_dump($media_url);
}
}
}
// TEST OUTPUT FOR DEBUGGING
//var_dump($ArrayPhotoURLs);
// COUNT IMAGES IN ARRAY OF TWITTER IMAGE URLS - TO BE USED BELOW TO CREATE DYNAMIC LIST / ANCHOR / IMG ITEMS
$imagecount = count($ArrayPhotoURLs);
// TEST OUTPUT FOR DEBUGGING
echo $imagecount;
?>
</head>
<?php // HTML LAYOUT CODE BEGINS HERE ?>
<body style="">
<div class="container">
<div>
<?php
// FOR LOOP, PRINT HTML WITH URL AS BOTH A HREF & IMG SRC PARAMETERS & ANCHOR TEXT
foreach ($ArrayPhotoURLs as $PhotoURL) {
echo '<a href="', $PhotoURL ,'">',
'<img src="',$PhotoURL, '">', $PhotoURL,
'</img></a><br/>';
}
?>
</div>
</div>
</body>
</html>
For those in a similar bind:
Firefox apparently treats the domain pbs.twimg.com as a tracker and blocks all connections made to this subdomain. Consider disabling Tracking Protection in your browser or implement a server-side shim to preload the images.
See:
https://bugzilla.mozilla.org/show_bug.cgi?id=1458915

Is there a way to pull an instagram feed with PHP without logging in?

It seems that this solution no longer works -
How to get a user's Instagram feed
The new API requires an access token which is dynamically assigned after passing through a login page. Is there a way to still pull a feed programmatically through PHP without jumping through the new oauth hoops? This is useful for setting a crontab to automatically save new posts to a database.
Yes you can. You don't need to login or access_token to get the latest 20 posts. You just need to parse the json content from https://www.instagram.com/[USERNAME]/media/.
Replace the [username] with the instagram user_name.
eg.
$instaResult = file_get_contents('https://www.instagram.com/'.$username.'/media/');
$insta = json_decode($instaResult);
UPDATE:
Instagram has changed the user media rss url. In order to get the rss feed you now have to use
https://www.instagram.com/[USERNAME]/?__a=1
UPDATE:
Instead of file_get_contents, it is better to use curl or Psr\Http\Message\RequestInterface based library like http://docs.guzzlephp.org/en/stable/
We can still access the photos. But just last 12 photo. If want more photos access_token require. This my way to get photos.
$instaResult = file_get_contents('https://www.instagram.com/'.$username.'/?__a=1');
$insta = json_decode($instaResult);
$instagram_photos = $insta->graphql->user->edge_owner_to_timeline_media->edges;
Now we get the last photos array.
Than i used in the view with foreach loop.
<ul>
#foreach($instagram_photos as $instagram_photo)
<li>
<img src="{{$instagram_photo->node->display_url}}">
</li>
#endforeach
</ul>
Try this php library: https://github.com/postaddictme/instagram-php-scraper
And here is example (https://github.com/postaddictme/instagram-php-scraper/blob/master/examples/getAccountMediasByUsername.php):
<?php
require __DIR__ . '/../vendor/autoload.php';
// If account is public you can query Instagram without auth
$instagram = new \InstagramScraper\Instagram();
$medias = $instagram->getMedias('kevin', 25);
// Let's look at $media
$media = $medias[0];
echo "Media info:\n";
echo "Id: {$media->getId()}\n";
echo "Shotrcode: {$media->getShortCode()}\n";
echo "Created at: {$media->getCreatedTime()}\n";
echo "Caption: {$media->getCaption()}\n";
echo "Number of comments: {$media->getCommentsCount()}";
echo "Number of likes: {$media->getLikesCount()}";
echo "Get link: {$media->getLink()}";
echo "High resolution image: {$media->getImageHighResolutionUrl()}";
echo "Media type (video or image): {$media->getType()}";
$account = $media->getOwner();
echo "Account info:\n";
echo "Id: {$account->getId()}\n";
echo "Username: {$account->getUsername()}\n";
echo "Full name: {$account->getFullName()}\n";
echo "Profile pic url: {$account->getProfilePicUrl()}\n";
// If account private you should be subscribed and after auth it will be available
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', 'path/to/cache/folder');
$instagram->login();
$medias = $instagram->getMedias('private_account', 100);

How to display a linked article's image, title, and description in my LAMP web app

I'm developing a social media platform using a LAMP build. So far my users can upload pictures and videos and comment and vote on them. I want users to be able to post a url link to an article, and have the title, image and description automatically pop up like it does on Facebook. I'm guessing that most web pages containing articles include some sort of meta data that would allow a developer like me to systematically access the title, description fields etc. If this is the case, then how specifically do I access this metadata. Otherwise, how does Facebook do it?
Thanks,
You can use a PHP HTML parsing library that allows you to input a URL, and break out meta information at your choosing.
This answer on StackOverflow has an excellent list of available HTML parsing options for PHP: https://stackoverflow.com/a/3577662/1332068
This scrapes all of the images off of whatever valid url you input:
<?php
if(isset($_POST['link'])){
$link = $_POST['link'];
$scrapings = "";
$article = new DOMDocument;
$article ->loadHTMLFile($link);
$titles = $article->getElementsByTagName("title");
foreach($titles as $title){
echo $title->nodeValue, PHP_EOL;
}
$images = $article->getElementsByTagName("img");
foreach($images as $image){
$source = $image->getAttribute("src");
$scrapings .= '<img src="'.$source.'" alt="default">';
}
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<form method="POST" action="article_system.php">
<input type="text" name="link">
<input type="submit" value="submit">
</form>
<?php echo $scrapings; ?>
</body>
</html>

Instagram PHP API: getTagMedia only works locally

I'm working with the Instagram PHP API (https://github.com/cosenary/Instagram-PHP-API) and I have used a solution I found which have been working perfectly (see #kexxcream 's answer for the solution here: Get all photos from Instagram which have a specific hashtag with PHP) until now obviously.. I can only get it to work locally but not at my referred domain that I have put in at my Instagram app. I have no idea if it has to do with my domain-bindings; my company (like most companies) got a dev-server which I've then binded to my domain. Though this has not been a problem before when I've used this solution for grabbing an instagram feed.
Anyway, does anyone know what the problem could be?
Here's my code:
<?php
// Get class for Instagram
// More examples here: https://github.com/cosenary/Instagram-PHP-API
require_once 'instagram.class.php';
// Initialize class with client_id
// Register at http://instagram.com/developer/ and replace client_id with your own
$instagram = new Instagram('09b639fa2d2845d99d7c3c748f273b30');
// Set keyword for #hashtag
$tag = 'insta';
// Get latest photos according to #hashtag keyword
$media = $instagram->getTagMedia($tag);
// Set number of photos to show
$limit = 8;
// Show results
// Using for loop will cause error if there are less photos than the limit
foreach(array_slice($media->data, 0, $limit) as $data)
{
#print('<pre>'); print_r($data); print('</pre>');
?>
<div class="insta-item">
<a href="<?php echo $data->link; ?>" target="_blank">
<img src="<?php echo $data->images->standard_resolution->url; ?>" height="46px" width="46px" alt="Pic" />
</a>
</div>
<?php
}
?>
First, I would recommend you to check your Instagram parameters.
There's a known issue about the usage on localhost of the api.
If this still doesn't work, try adding a limit to the number of image loaded:
$media = $instagram->getTagMedia($tag, 10);

Ordering content from the YouTube API with PHP & XML

I've got a nice little web app working that brings down playlists and videos from YouTube using the API. However, YouTube seems to fire back the playlists in the wrong order.
Any idea how I can do that?
Here is my very simple PHP code that does everything I need it to do (apart from date ordering)
<?php
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/users/popcorncomedy/playlists?v=2';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
?>
<div class="container">
<h1><?php echo $sxml->title; ?></h1>
<?php
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get <yt:duration> node for video length
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
?>
<a href="videos.php?playlist=<?php echo $yt->playlistId; ?>"><div class="item">
<span class="title"><?php echo $entry->title; ?></span><br /><br />
<span class="summary"><?php echo $entry->summary; ?></span>
</div></a>
<?php
} // closes the loop
?>
The XML element that contains the date is called: published in the date format: 2010-03-03T17:37:34.000Z
Any thoughts on how to achieve this simply?
I can't find a function within the API itself that orders content for you.
What you want is the orderby parameter http://code.google.com/apis/youtube/2.0/developers_guide_protocol_api_query_parameters.html#orderbysp however I haven't gotten it to work for playlists yet. As far as I can find its supports work with palylists but I never seen it work, hopefully you will have better luck!

Categories