-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a method to set user agent, language and login with cookies (#304)
* add method to set user agent and language * add login method with cookies * fix update session after login with cookies * Add a method to access response of each request
- Loading branch information
Showing
16 changed files
with
379 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Instagram\Api; | ||
use Instagram\Auth\Session; | ||
use Instagram\Utils\CacheHelper; | ||
use Instagram\Exception\{InstagramException, InstagramAuthException}; | ||
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | ||
|
||
require realpath(dirname(__FILE__)) . '/../vendor/autoload.php'; | ||
$credentials = include_once realpath(dirname(__FILE__)) . '/credentials.php'; | ||
|
||
$cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/../cache'); | ||
|
||
// Make sure you are logged in with the login() method before using this example | ||
// See examples in https://github.com/pgrimaud/instagram-user-feed/blob/5b2358f9918b84c11b7d193f7f3205df87b35793/examples/profile.php#L17-L18 | ||
$sessionData = $cachePool->getItem(Session::SESSION_KEY . '.' . CacheHelper::sanitizeUsername($credentials->getLogin())); | ||
$cookies = $sessionData->get(); | ||
|
||
try { | ||
$api = new Api(); | ||
|
||
// Optionals for set user agent and language | ||
$api->setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.57 Safari/537.36'); | ||
$api->setLanguage('id-ID'); | ||
|
||
$api->loginWithCookies($cookies); | ||
|
||
$profile = $api->getProfile('robertdowneyjr'); | ||
|
||
dd($profile); | ||
} catch (InstagramAuthException $e) { | ||
print_r($e->getMessage()); | ||
} catch (InstagramException $e) { | ||
print_r($e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.