|
7 | 7 | use Instagram\Utils\CacheHelper;
|
8 | 8 | use Instagram\Exception\{InstagramException, InstagramAuthException};
|
9 | 9 | use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
| 10 | +use GuzzleHttp\Cookie\{SetCookie, CookieJar}; |
10 | 11 |
|
11 | 12 | require realpath(dirname(__FILE__)) . '/../vendor/autoload.php';
|
12 | 13 | $credentials = include_once realpath(dirname(__FILE__)) . '/credentials.php';
|
13 | 14 |
|
14 | 15 | $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/../cache');
|
15 | 16 |
|
16 |
| -// Make sure you are logged in with the login() method before using this example |
17 |
| -// See examples in https://github.com/pgrimaud/instagram-user-feed/blob/5b2358f9918b84c11b7d193f7f3205df87b35793/examples/profile.php#L17-L18 |
18 |
| -$sessionData = $cachePool->getItem(Session::SESSION_KEY . '.' . CacheHelper::sanitizeUsername($credentials->getLogin())); |
19 |
| -$cookies = $sessionData->get(); |
| 17 | +/** |
| 18 | + * Make sure you are logged in with the login() method before using example "1. Get cookies from file" |
| 19 | + * See examples in https://github.com/pgrimaud/instagram-user-feed/blob/5b2358f9918b84c11b7d193f7f3205df87b35793/examples/profile.php#L17-L18 |
| 20 | + */ |
| 21 | + |
| 22 | +/** 1. Get cookies from file */ |
| 23 | +$sessionId = $cachePool->getItem(Session::SESSION_KEY . '.' . CacheHelper::sanitizeUsername($credentials->getLogin())) |
| 24 | + ->get() |
| 25 | + ->getCookieByName('sessionId'); |
| 26 | + |
| 27 | +// Generate CookieJar from instagram cookie 'sessionid' |
| 28 | +$cookieJar = new CookieJar(false, [$sessionId]); |
| 29 | + |
| 30 | +/** 2. Insert cookies manually |
| 31 | +$sessionId = new SetCookie([ |
| 32 | + "Name" => "sessionid", |
| 33 | + "Value" => "YOUR_INSTAGRAM_SESSIONID", |
| 34 | + "Domain" => ".instagram.com", |
| 35 | + "Path" => "/", |
| 36 | + "Expires" => "YOUR_INSTAGRAM_SESSIONID_EXPIRES", |
| 37 | + "Max-Age" => "31536000", |
| 38 | + "Secure" => true, |
| 39 | + "Discard" => false, |
| 40 | + "HttpOnly" => true, |
| 41 | +]); |
| 42 | +
|
| 43 | +// Generate CookieJar from instagram cookie 'sessionid' |
| 44 | +$cookieJar = new CookieJar(false, [$sessionId]); |
| 45 | +*/ |
20 | 46 |
|
21 | 47 | try {
|
22 | 48 | $api = new Api();
|
|
25 | 51 | $api->setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.57 Safari/537.36');
|
26 | 52 | $api->setLanguage('id-ID');
|
27 | 53 |
|
28 |
| - $api->loginWithCookies($cookies); |
| 54 | + $api->loginWithCookies($cookieJar); |
29 | 55 |
|
30 | 56 | $profile = $api->getProfile('robertdowneyjr');
|
31 | 57 |
|
|
0 commit comments