P
P
picka2021-03-04 02:40:05
PHP
picka, 2021-03-04 02:40:05

Why does Class 'GuzzleHttp\Client' not found when loading a project through Composer?

I ran this command in the project:
composer require raiym/instagram-php-scraper
Everything loaded: I
60401d8a88540558656007.png
created a separate index.php file, into which I inserted the code from the example of this library:

use Phpfastcache\Helper\Psr16Adapter;

require __DIR__ . '/vendor/autoload.php';

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());

$media = $instagram->getMediaByUrl('https://www.instagram.com/p/BHaRdodBouH');
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";


As a result, an error about not finding the class comes out
Fatal error: Uncaught Error: Class 'GuzzleHttp\Client' not found in /Users/picka/Desktop/instagram-php-scraper-master/index.php on line 11</b>
Error: Class 'GuzzleHttp\Client' not found in /Users/picka/Desktop/instagram-php-scraper-master/index.php on line 11


I run all this through MAMP PRO 5.7, PHP version 7.2.22

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
smilingcheater, 2021-03-04
@smilingcheater

When you create a new scrapper instance

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());

you pass new \GuzzleHttp\Client to it as input, but you don't have this package installed (judging by the inscription on the screen ./composer.json has been created, you don't have anything else installed at all). Install it too.
composer require guzzlehttp/guzzle
In general - an elementary mistake, learn to carefully read and google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question