Search code examples
facebook-graph-apiinstagraminstagram-api

Instagram - How to get media based on a given hashtag?


I am trying to write an Instagram app which among others will let me get media based on a hashtag. I already finished it, and only then noticed this message from Instagram in the developer page.

Starting 10/1/2017, all permissions other than the basic permission will be unavailable to submit for or obtain.

Query by hashtag needs the public_content permission. Looks like this is not possible anymore.

Are there any other options? I tried to look for similar functionality with Facebook graph api but didn't find anything interesting.


Solution

  • Try this PHP library: https://github.com/postaddictme/instagram-php-scraper

    or Java library: https://github.com/postaddictme/instagram-java-scraper

    Example:

    https://github.com/postaddictme/instagram-php-scraper/blob/master/examples/getMediasByTag.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 "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";