Skip to content

Commit b265382

Browse files
author
Sergei Gulin
authored
Psr18 (#796)
* add psr-18 http client * upd README.md * upd phpunit * guzzlehttp/psr7
1 parent cd9e475 commit b265382

34 files changed

+193
-103
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
This library is based on the Instagram web version. We develop it because nowadays it is hard to get an approved Instagram application. The purpose is to support every feature that the web desktop and mobile version support.
33

44
## Dependencies
5-
5+
- PHP >= 7.2
66
- [PSR-16](http://www.php-fig.org/psr/psr-16/)
7+
- [PSR-18](http://www.php-fig.org/psr/psr-18/)
78

89

910
## Code Example
1011
```php
11-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password');
12+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password');
1213
$instagram->login();
1314
$account = $instagram->getAccountById(3);
1415
echo $account->getUsername();
1516
```
1617

1718
Some methods do not require authentication:
1819
```php
19-
$instagram = new \InstagramScraper\Instagram();
20+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
2021
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
2122
echo $nonPrivateAccountMedias[0]->getLink();
2223
```
@@ -26,7 +27,7 @@ If you use authentication it is recommended to cache the user session. In this c
2627
```php
2728
use Phpfastcache\Helper\Psr16Adapter;
2829

29-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
30+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
3031
$instagram->login(); // will use cached session if you want to force login $instagram->login(true)
3132
$instagram->saveSession(); //DO NOT forget this in order to save the session, otherwise have no sense
3233
$account = $instagram->getAccountById(3);
@@ -36,16 +37,11 @@ echo $account->getUsername();
3637
Using proxy for requests:
3738

3839
```php
39-
$instagram = new \InstagramScraper\Instagram();
40-
Instagram::setProxy([
41-
'address' => '111.112.113.114',
42-
'port' => '8080',
43-
'tunnel' => true,
44-
'timeout' => 30,
45-
]);
40+
// https://docs.guzzlephp.org/en/stable/request-options.html#proxy
41+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client(['proxy' => 'tcp://localhost:8125']));
4642
// Request with proxy
4743
$account = $instagram->getAccount('kevin');
48-
Instagram::disableProxy();
44+
\InstagramScraper\Instagram::setHttpClient(new \GuzzleHttp\Client());
4945
// Request without proxy
5046
$account = $instagram->getAccount('kevin');
5147
```

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.4.0",
19-
"mashape/unirest-php": "3.0.*",
18+
"php": ">=7.2",
2019
"ext-curl": "*",
2120
"ext-json": "*",
22-
"psr/simple-cache": "~1.0"
21+
"psr/simple-cache": "~1.0",
22+
"psr/http-client": "~1.0",
23+
"guzzlehttp/psr7": "^1.7"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "5.5.*",
26-
"phpfastcache/phpfastcache": "^7.1"
26+
"phpunit/phpunit": "^7.0",
27+
"phpfastcache/phpfastcache": "^7.1",
28+
"guzzlehttp/guzzle": "^7.2"
2729
},
2830
"autoload": {
2931
"psr-4": {

examples/addAndDeleteComment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
7+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
88
$instagram->login();
99

1010
try {

examples/getAccountById.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
require __DIR__ . '/../vendor/autoload.php';
33

4-
$account = (new \InstagramScraper\Instagram())->getAccountById('3');
4+
$account = (new \InstagramScraper\Instagram(new \GuzzleHttp\Client()))->getAccountById('3');
55

66
// Available fields
77
echo "Account info:\n";

examples/getAccountByUsername.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// If account is public you can query Instagram without auth
55

6-
$instagram = new \InstagramScraper\Instagram();
6+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
77

88
// For getting information about account you don't need to auth:
99

examples/getAccountFollowers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88
sleep(2); // Delay to mimic user
99

examples/getAccountFollowings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88
sleep(2); // Delay to mimic user
99

examples/getAccountMediasByUsername.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// If account is public you can query Instagram without auth
77

8-
$instagram = new \InstagramScraper\Instagram();
8+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
99
$medias = $instagram->getMedias('kevin', 25);
1010

1111
// Let's look at $media
@@ -30,6 +30,6 @@
3030

3131

3232
// If account private you should be subscribed and after auth it will be available
33-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
33+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
3434
$instagram->login();
3535
$medias = $instagram->getMedias('private_account', 100);

examples/getCurrentTopMediasByLocationId.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$medias = $instagram->getCurrentTopMediasByLocationId('1');

examples/getCurrentTopMediasByTagName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$medias = $instagram->getCurrentTopMediasByTagName('youneverknow');

examples/getFeed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use InstagramScraper\Instagram;
55
use Phpfastcache\Helper\Psr16Adapter;
66

7-
$instagram = Instagram::withCredentials('login', 'password', new Psr16Adapter('Files'));
7+
$instagram = Instagram::withCredentials(new \GuzzleHttp\Client(), 'login', 'password', new Psr16Adapter('Files'));
88
$instagram->login();
99
$instagram->saveSession();
1010

examples/getHighlights.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$userId = $instagram->getAccount('instagram')->getId();

examples/getLocationById.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
// Location id from facebook

examples/getMediaByCode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
require __DIR__ . '/../vendor/autoload.php';
66

77
// If account is public you can query Instagram without auth
8-
$instagram = new \InstagramScraper\Instagram();
8+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
99

1010
// If account is private and you subscribed to it, first login
11-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
11+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
1212
$instagram->login();
1313

1414
$media = $instagram->getMediaByCode('BHaRdodBouH');

examples/getMediaById.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
require __DIR__ . '/../vendor/autoload.php';
55

66
// If account is public you can query Instagram without auth
7-
$instagram = new \InstagramScraper\Instagram();
7+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
88

99
// If account is private and you subscribed to it, first login
10-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
10+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
1111
$instagram->login();
1212

1313
$media = $instagram->getMediaById('1270593720437182847');

examples/getMediaByUrl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
require __DIR__ . '/../vendor/autoload.php';
55

66
// If account is public you can query Instagram without auth
7-
$instagram = new \InstagramScraper\Instagram();
7+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
88

99
// If account is private and you subscribed to it, first login
10-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
10+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
1111
$instagram->login();
1212

1313
$media = $instagram->getMediaByUrl('https://www.instagram.com/p/BHaRdodBouH');

examples/getMediaComments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
// Get media comments by shortcode

examples/getMediasByLocationId.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$medias = $instagram->getMediasByLocationId('1', 20);

examples/getMediasByTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$medias = $instagram->getMediasByTag('youneverknow', 20);

examples/getPaginateMediasByTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$result = $instagram->getPaginateMediasByTag('zara');

examples/getPaginateMediasByUsername.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
require __DIR__ . '/../vendor/autoload.php';
33

4-
$instagram = new \InstagramScraper\Instagram();
4+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
55
$response = $instagram->getPaginateMedias('kevin');
66

77
foreach ($response['medias'] as $media) {

examples/getSidecarMediaByUrl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function printMediaInfo(\InstagramScraper\Model\Media $media, $padding = '') {
1616
}
1717

1818
// If account is public you can query Instagram without auth
19-
$instagram = new \InstagramScraper\Instagram();
19+
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
2020

2121
// If account is private and you subscribed to it firstly login
22-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
22+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
2323
$instagram->login();
2424

2525
$media = $instagram->getMediaByUrl('https://www.instagram.com/p/BQ0lhTeAYo5');

examples/getStories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$stories = $instagram->getStories();

examples/getThreads.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88
$instagram->saveSession();
99

examples/likeAndUnlikeMedia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
7+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
88
$instagram->login();
99

1010
try {

examples/paginateAccountMediaByUsername.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require __DIR__ . '/../vendor/autoload.php';
44

55
// getPaginateMedias() works with and without authentication
6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99
$result = $instagram->getPaginateMedias('kevin');

examples/searchAccountsByUsername.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', new Psr16Adapter('Files'));
6+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
77
$instagram->login();
88

99

examples/setCustomCookies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ds_user_id" => "36*****872",
1616
];
1717

18-
$instagram = \InstagramScraper\Instagram::withCredentials($this->instaUsername, $this->instaPassword, new Psr16Adapter('Files'));
18+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), $this->instaUsername, $this->instaPassword, new Psr16Adapter('Files'));
1919
$instagram->setUserAgent('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0');
2020
$instagram->setCustomCookies($newCookie);
2121
$instagram->login();

examples/twoStepAutoVerification/loginWithEmailAutoCponfirm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* EmailVerification requires https://packagist.org/packages/php-mail-client/client
77
*/
88

9-
$instagram = \InstagramScraper\Instagram::withCredentials('user', 'password');
9+
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'user', 'password', new \Phpfastcache\Helper\Psr16Adapter('Files'));
1010

1111
$emailVecification = new EmailVerification(
1212
'user@mail.ru',

src/InstagramScraper/Endpoints.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Endpoints
66
{
77
const BASE_URL = 'https://www.instagram.com';
88
const LOGIN_URL = 'https://www.instagram.com/accounts/login/ajax/';
9-
const ACCOUNT_PAGE = 'https://www.instagram.com/{username}';
9+
const ACCOUNT_PAGE = 'https://www.instagram.com/{username}/';
1010
const MEDIA_LINK = 'https://www.instagram.com/p/{code}';
1111
const ACCOUNT_MEDIAS = 'https://www.instagram.com/graphql/query/?query_hash=e769aa130647d2354c40ea6a439bfc08&variables={variables}';
1212
const ACCOUNT_JSON_INFO = 'https://www.instagram.com/{username}/?__a=1';

0 commit comments

Comments
 (0)