Skip to content

Commit

Permalink
Merge pull request #4 from postaddictme/master
Browse files Browse the repository at this point in the history
Update from source
  • Loading branch information
Mulkave authored May 7, 2018
2 parents bc5e31a + 8153e49 commit 4433c50
Show file tree
Hide file tree
Showing 7 changed files with 555 additions and 269 deletions.
6 changes: 2 additions & 4 deletions examples/getAccountById.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder');
$instagram->login();
$account = $instagram->getAccountById('3');
$account = (new \InstagramScraper\Instagram())->getAccountById('3');

// Available fields
echo "Account info:\n";
Expand All @@ -17,4 +15,4 @@
echo "Number of followers: {$account->getFollowedByCount()}\n";
echo "Number of follows: {$account->getFollowsCount()}\n";
echo "Is private: {$account->isPrivate()}\n";
echo "Is verified: {$account->isVerified()}\n";
echo "Is verified: {$account->isVerified()}\n";
31 changes: 31 additions & 0 deletions examples/getPaginateMediasByUsername.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$instagram = new \InstagramScraper\Instagram();
$response = $instagram->getPaginateMedias('kevin');

foreach ($response['medias'] as $media) {
/** @var \InstagramScraper\Model\Media $media */

echo "Media info:" . PHP_EOL;
echo "Id: {$media->getId()}" . PHP_EOL;
echo "Shotrcode: {$media->getShortCode()}" . PHP_EOL;
echo "Created at: {$media->getCreatedTime()}" . PHP_EOL;
echo "Caption: {$media->getCaption()}" . PHP_EOL;
echo "Number of comments: {$media->getCommentsCount()}" . PHP_EOL;
echo "Number of likes: {$media->getLikesCount()}" . PHP_EOL;
echo "Get link: {$media->getLink()}" . PHP_EOL;
echo "High resolution image: {$media->getImageHighResolutionUrl()}" . PHP_EOL;
echo "Media type (video or image): {$media->getType()}" . PHP_EOL . PHP_EOL;
$account = $media->getOwner();

echo "Account info:" . PHP_EOL;
echo "Id: {$account->getId()}" . PHP_EOL;
echo "Username: {$account->getUsername()}" . PHP_EOL;
echo "Full name: {$account->getFullName()}" . PHP_EOL;
echo "Profile pic url: {$account->getProfilePicUrl()}" . PHP_EOL;
echo PHP_EOL . PHP_EOL;
}

echo "HasNextPage: {$response['hasNextPage']}" . PHP_EOL;
echo "MaxId: {$response['maxId']}" . PHP_EOL;
28 changes: 24 additions & 4 deletions src/InstagramScraper/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Endpoints
const LOGIN_URL = 'https://www.instagram.com/accounts/login/ajax/';
const ACCOUNT_PAGE = 'https://www.instagram.com/{username}';
const MEDIA_LINK = 'https://www.instagram.com/p/{code}';
const ACCOUNT_MEDIAS = 'https://instagram.com/graphql/query/?query_id=17888483320059182&id={user_id}&first=30&after={max_id}';
const ACCOUNT_MEDIAS = 'https://www.instagram.com/graphql/query/?query_hash=42323d64886122307be10013ad2dcc44&variables={variables}';
const ACCOUNT_JSON_INFO = 'https://www.instagram.com/{username}/?__a=1';
const MEDIA_JSON_INFO = 'https://www.instagram.com/p/{code}/?__a=1';
const MEDIA_JSON_BY_LOCATION_ID = 'https://www.instagram.com/explore/locations/{{facebookLocationId}}/?__a=1&max_id={{maxId}}';
Expand All @@ -26,6 +26,7 @@ class Endpoints
const USER_FEED2 = 'https://www.instagram.com/?__a=1';
const INSTAGRAM_QUERY_URL = 'https://www.instagram.com/query/';
const INSTAGRAM_CDN_URL = 'https://scontent.cdninstagram.com/';
const ACCOUNT_JSON_PRIVATE_INFO_BY_ID = 'https://i.instagram.com/api/v1/users/{userId}/info/';

const ACCOUNT_MEDIAS2 = 'https://www.instagram.com/graphql/query/?query_id=17880160963012870&id={{accountId}}&first=10&after=';

Expand All @@ -34,6 +35,21 @@ class Endpoints

const GRAPH_QL_QUERY_URL = 'https://www.instagram.com/graphql/query/?query_id={{queryId}}';

private static $requestMediaCount = 30;

/**
* @param int $count
*/
public static function setAccountMediasRequestCount($count)
{
static::$requestMediaCount = $count;
}

public static function getAccountMediasRequestCount()
{
return static::$requestMediaCount;
}

public static function getAccountPageLink($username)
{
return str_replace('{username}', urlencode($username), static::ACCOUNT_PAGE);
Expand All @@ -49,10 +65,14 @@ public static function getAccountJsonInfoLinkByAccountId($id)
return str_replace('{userId}', urlencode($id), static::ACCOUNT_JSON_INFO_BY_ID);
}

public static function getAccountMediasJsonLink($userId, $maxId = '')
public static function getAccountJsonPrivateInfoLinkByAccountId($id)
{
return str_replace('{userId}', urlencode($id), static::ACCOUNT_JSON_PRIVATE_INFO_BY_ID);
}

public static function getAccountMediasJsonLink($variables)
{
$url = str_replace('{user_id}', urlencode($userId), static::ACCOUNT_MEDIAS);
return str_replace('{max_id}', urlencode($maxId), $url);
return str_replace('{variables}', urlencode($variables), static::ACCOUNT_MEDIAS);
}

public static function getMediaPageLink($code)
Expand Down
Loading

0 comments on commit 4433c50

Please sign in to comment.