10/07/2019

How to display your instagram photos in events by hashtag

9

Not so long time ago, maybe few years, I used to use a third party software in order to display a collection of photos from Instagram sharing the same #hashtag. The purpose is to add more fun to the event, so our guest can have their selfies or wefies on instagram, put a common #hashtag to it, then boom!.. their pictures are display on the event big screens or somewhere.

But few weeks back, I noticed that this service is not around anymore. Got info somewhere that Instagram already limit their API and that kind of operation is not allowed anymore.

But I was in rush to get the #hashtag display done. So I decided to have my own service for this purpose. It will be used in a single day, and our aim is to get it done at minimum cost.. or FREE. Ok I chose to have it done at no cost.

Here are the elements needed:

  1. A web server with public IP address (well it can be local IP, but as I said I need it quite urgent and the development environment and real event were different locations, so I need the server to be publicly accessible). Guess what? A Google Cloud VM will do. So I just pick one, configure with Linux, Apache, MySQL and PHP (LAMP). Make sure to have the web server running at this point so you get http://ipaddress/ working fine.
  2. Not to forget, install composer on the server.
  3. Then I need a fast script. I did not want to write my own, I need it fast, so I searched Github and found some good scripts for this purpose). Here is the script that I used. So I went straight to searchMediabyHash.php for this purpose.
<?php
require __DIR__ . '/../vendor/autoload.php';

$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder');
$instagram->login();

$medias = $instagram->getMediasByTag('youneverknow', 20);
$media = $medias[0];
echo "Media info:\n";
echo "Id: {$media->getId()}\n";
echo "Shortcode: {$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";
?>

4. I could not get the above code working at first, until I commented out this line:

$instagram->login();

5. Customizing an HTML file to self refresh every 5 minutes, so It will fetch newly tagged photos as long as the event is running.

6. To make it better look, I used WOWSlider. It’s a windows standalone program, so I get it running, picked a template and have it run on some dummy photos, then configured the given code to fetch photos from Instagram.

About Author Mr.Bazz

Hi thanks for dropping by. Please share the content if you think there is someone who will appreciate it.

Leave A Comment

Your email address will not be published. Required fields are marked *