PHP code example of ravelinodecastro / instagram-php-scraper

1. Go to this page and download the library: Download ravelinodecastro/instagram-php-scraper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ravelinodecastro / instagram-php-scraper example snippets


$instagram = new \InstagramScraper\Instagram();
$instagram->getProxyApiUrl('https://instagram40.p.rapidapi.com/proxy?url={instagram_url}'); // do not remove {instagram_url}, it is later replaced by the instagram endpoints
$instagram->setHeaders(['x-rapidapi-key'=>'YOUR-RAPID-API-KEY']); // this is where you add your api key
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
echo $nonPrivateAccountMedias[0]->getLink();

$instagram = new \InstagramScraper\Instagram();
$instagram->getProxyApiUrl('http://api.scraperapi.com?api_key=YOUR-SCRAPPER-API-KEY&url={instagram_url}'); // do not remove {instagram_url}, it is later replaced by the instagram endpoints
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
echo $nonPrivateAccountMedias[0]->getLink();

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password');
$instagram->login();
$account = $instagram->getAccountById(3);
echo $account->getUsername();

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
echo $nonPrivateAccountMedias[0]->getLink();

use Phpfastcache\Helper\Psr16Adapter;

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
$instagram->login(); // will use cached session if you want to force login $instagram->login(true)
$instagram->saveSession();  //DO NOT forget this in order to save the session, otherwise have no sense
$account = $instagram->getAccountById(3);
echo $account->getUsername();

// https://docs.guzzlephp.org/en/stable/request-options.html#proxy
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client(['proxy' => 'tcp://localhost:8125']));
// Request with proxy
$account = $instagram->getAccount('kevin');
\InstagramScraper\Instagram::setHttpClient(new \GuzzleHttp\Client());
// Request without proxy
$account = $instagram->getAccount('kevin');
sh
composer.phar