-
-
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.
- Loading branch information
Showing
16 changed files
with
393 additions
and
60 deletions.
There are no files selected for viewing
File renamed without changes.
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,117 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$cache = new Instagram\Storage\CacheManager(__DIR__ . '/../cache/'); | ||
|
||
try { | ||
|
||
$api = new Instagram\Api($cache); | ||
$api->login('username', 'password'); | ||
$api->setUserName('pgrimaud'); | ||
|
||
// First page | ||
|
||
/** @var \Instagram\Hydrator\Component\Feed $feed */ | ||
$feed = $api->getFeed(); | ||
|
||
echo '============================' . "\n"; | ||
echo 'User Informations : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
echo 'ID : ' . $feed->getId() . "\n"; | ||
echo 'Full Name : ' . $feed->getFullName() . "\n"; | ||
echo 'UserName : ' . $feed->getUserName() . "\n"; | ||
echo 'Following : ' . $feed->getFollowing() . "\n"; | ||
echo 'Followers : ' . $feed->getFollowers() . "\n\n"; | ||
|
||
echo '============================' . "\n"; | ||
echo 'Medias first page : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
/** @var \Instagram\Hydrator\Component\Media $media */ | ||
foreach ($feed->getMedias() as $media) { | ||
echo 'ID : ' . $media->getId() . "\n"; | ||
echo 'Caption : ' . $media->getCaption() . "\n"; | ||
echo 'Link : ' . $media->getLink() . "\n"; | ||
echo 'Likes : ' . $media->getLikes() . "\n"; | ||
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n"; | ||
echo '============================' . "\n"; | ||
} | ||
|
||
// Second page | ||
|
||
$api->setEndCursor($feed->getEndCursor()); | ||
|
||
sleep(1); // avoir 429 Rate limit from Instagram | ||
|
||
$feed = $api->getFeed(); | ||
|
||
echo "\n\n"; | ||
echo '============================' . "\n"; | ||
echo 'Medias third page : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
/** @var \Instagram\Hydrator\Component\Media $media */ | ||
foreach ($feed->getMedias() as $media) { | ||
echo 'ID : ' . $media->getId() . "\n"; | ||
echo 'Caption : ' . $media->getCaption() . "\n"; | ||
echo 'Link : ' . $media->getLink() . "\n"; | ||
echo 'Likes : ' . $media->getLikes() . "\n"; | ||
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n"; | ||
echo '============================' . "\n"; | ||
} | ||
|
||
// Third page | ||
|
||
$api->setEndCursor($feed->getEndCursor()); | ||
|
||
sleep(1); // avoir 429 Rate limit from Instagram | ||
|
||
$feed = $api->getFeed(); | ||
|
||
echo "\n\n"; | ||
echo '============================' . "\n"; | ||
echo 'Medias fourth page : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
/** @var \Instagram\Hydrator\Component\Media $media */ | ||
foreach ($feed->getMedias() as $media) { | ||
echo 'ID : ' . $media->getId() . "\n"; | ||
echo 'Caption : ' . $media->getCaption() . "\n"; | ||
echo 'Link : ' . $media->getLink() . "\n"; | ||
echo 'Likes : ' . $media->getLikes() . "\n"; | ||
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n"; | ||
echo '============================' . "\n"; | ||
} | ||
|
||
// Fourth Page | ||
|
||
$api->setEndCursor($feed->getEndCursor()); | ||
|
||
sleep(1); // avoir 429 Rate limit from Instagram | ||
|
||
$feed = $api->getFeed(); | ||
|
||
echo "\n\n"; | ||
echo '============================' . "\n"; | ||
echo 'Medias second page : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
/** @var \Instagram\Hydrator\Component\Media $media */ | ||
foreach ($feed->getMedias() as $media) { | ||
echo 'ID : ' . $media->getId() . "\n"; | ||
echo 'Caption : ' . $media->getCaption() . "\n"; | ||
echo 'Link : ' . $media->getLink() . "\n"; | ||
echo 'Likes : ' . $media->getLikes() . "\n"; | ||
echo 'Date : ' . $media->getDate()->format('Y-m-d h:i:s') . "\n"; | ||
echo '============================' . "\n"; | ||
} | ||
|
||
// And etc... | ||
|
||
} catch (Exception $exception) { | ||
print_r($exception->getMessage()); | ||
} catch (\GuzzleHttp\Exception\GuzzleException $e) { | ||
print_r($exception->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
try { | ||
$cache = new Instagram\Storage\CacheManager(__DIR__ . '/../cache/'); | ||
|
||
$api = new Instagram\Api($cache); | ||
$api->login('username', 'password'); | ||
$api->setUserName('pgrimaud'); | ||
|
||
// only the first page | ||
/** @var \Instagram\Hydrator\Component\Feed $feed */ | ||
$feed = $api->getFeed(); | ||
|
||
echo '============================' . "\n"; | ||
echo 'User Informations : ' . "\n"; | ||
echo '============================' . "\n\n"; | ||
|
||
echo 'ID : ' . $feed->getId() . "\n"; | ||
echo 'Full Name : ' . $feed->getFullName() . "\n"; | ||
echo 'UserName : ' . $feed->getUserName() . "\n"; | ||
echo 'Following : ' . $feed->getFollowing() . "\n"; | ||
echo 'Followers : ' . $feed->getFollowers() . "\n"; | ||
echo 'Biography : ' . $feed->getBiography() . "\n"; | ||
echo 'External Url : ' . $feed->getExternalUrl() . "\n"; | ||
echo 'Profile Picture : ' . $feed->getProfilePicture() . "\n"; | ||
echo 'Verified Account : ' . ($feed->isVerified() ? 'Yes' : 'No') . "\n"; | ||
echo 'Private Account : ' . ($feed->isPrivate() ? 'Yes' : 'No') . "\n"; | ||
echo 'Media Count : ' . $feed->getMediaCount() . "\n\n"; | ||
|
||
} catch (Exception $exception) { | ||
print_r($exception->getMessage()); | ||
} catch (\GuzzleHttp\Exception\GuzzleException $e) { | ||
print_r($exception->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Instagram\Auth; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Cookie\CookieJar; | ||
use Instagram\Exception\InstagramAuthException; | ||
use Instagram\Exception\InstagramException; | ||
use Instagram\Transport\TransportFeed; | ||
|
||
class Login | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param Client|null $client | ||
*/ | ||
public function __construct(Client $client = null) | ||
{ | ||
$this->client = $client ?: new Client(); | ||
} | ||
|
||
/** | ||
* @param $username | ||
* @param $password | ||
* | ||
* @return CookieJar | ||
* | ||
* @throws InstagramAuthException | ||
* @throws InstagramException | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function execute($username, $password) | ||
{ | ||
$query = $this->client->request('GET', TransportFeed::BASE_URL, [ | ||
'headers' => [ | ||
'user-agent' => TransportFeed::USER_AGENT | ||
] | ||
]); | ||
|
||
$html = (string)$query->getBody(); | ||
|
||
preg_match('/<script type="text\/javascript">window\._sharedData\s?=(.+);<\/script>/', $html, $matches); | ||
|
||
if (!isset($matches[1])) { | ||
throw new InstagramException('Unable to extract JSON data'); | ||
} | ||
|
||
$data = json_decode($matches[1]); | ||
|
||
$cookieJar = new CookieJar(); | ||
|
||
$query = $this->client->request('POST', TransportFeed::AUTH_URL, [ | ||
'form_params' => [ | ||
'username' => $username, | ||
'password' => $password, | ||
], | ||
'headers' => [ | ||
'cookie' => 'ig_cb=1; csrftoken=' . $data->config->csrf_token, | ||
'referer' => TransportFeed::BASE_URL, | ||
'x-csrftoken' => $data->config->csrf_token, | ||
'user-agent' => TransportFeed::USER_AGENT, | ||
], | ||
'cookies' => $cookieJar | ||
]); | ||
|
||
if ($query->getStatusCode() !== 200) { | ||
throw new InstagramAuthException('Unknown error'); | ||
} else { | ||
$response = json_decode((string)$query->getBody()); | ||
if ($response->authenticated == true) { | ||
return $cookieJar; | ||
} else { | ||
throw new InstagramAuthException('Wrong login / password'); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
<?php | ||
|
||
namespace Instagram\Exception; | ||
|
||
class InstagramAuthException extends \Exception | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Instagram\Exception; | ||
|
||
class InstagramCacheException extends \Exception | ||
{ | ||
} |
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.