Skip to content

Commit c251f60

Browse files
author
Calvin Schemanski
authored
Add Instagram.php session helper functions and update Media keys (#1036)
* Add Account fields add fbid, has_clips, has_guides, category_name * Avoid extra login request before setting cached session * return session * Update Media properties Instagram's web api recently updated and some values still need to be replaced. * Update Media.php * add id to carousel media * update createdTime property
1 parent 7297fad commit c251f60

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/InstagramScraper/Instagram.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,27 @@ public static function withCredentials(ClientInterface $client, $username, $pass
9292
return $instance;
9393
}
9494

95+
/**
96+
* @param ClientInterface $client
97+
* @param string $username
98+
* @param CacheInterface $cache
99+
*
100+
* @return Instagram
101+
*/
102+
public static function withUsername(ClientInterface $client, $username, $cache)
103+
{
104+
static::$instanceCache = $cache;
105+
$instance = new self($client);
106+
$instance->sessionUsername = $username;
107+
return $instance;
108+
}
109+
110+
public function loadSession()
111+
{
112+
$session = static::$instanceCache->get($this->getCacheKey());
113+
$this->userSession = $session;
114+
return $session;
115+
}
95116
/**
96117
* @param string $tag
97118
*

src/InstagramScraper/Model/CarouselMedia.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
*/
99
class CarouselMedia
1010
{
11+
/**
12+
* @var string
13+
*/
14+
private $id;
15+
1116
/**
1217
* @var string
1318
*/
@@ -61,6 +66,25 @@ public function __construct()
6166
return $this;
6267
}
6368

69+
/**
70+
* @return mixed
71+
*/
72+
public function getId()
73+
{
74+
return $this->id;
75+
}
76+
77+
/**
78+
* @param mixed $id
79+
*
80+
* @return $this
81+
*/
82+
public function setId($id)
83+
{
84+
$this->id = $id;
85+
return $this;
86+
}
87+
6488
/**
6589
* @return mixed
6690
*/

src/InstagramScraper/Model/Media.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,14 @@ public function getLocationAddress()
571571
protected function initPropertiesCustom($value, $prop, $arr)
572572
{
573573
switch ($prop) {
574-
case 'id':
574+
case 'pk':
575575
$this->id = $value;
576576
break;
577577
case 'type':
578578
$this->type = $value;
579579
break;
580580
case 'date':
581+
case 'taken_at':
581582
case 'created_time':
582583
$this->createdTime = (int)$value;
583584
break;
@@ -674,7 +675,7 @@ protected function initPropertiesCustom($value, $prop, $arr)
674675
break;
675676
case 'location':
676677
if (isset($arr[$prop])) {
677-
$this->locationId = $arr[$prop]['id'] ?? null;
678+
$this->locationId = $arr[$prop]['pk'] ?? null;
678679
$this->locationName = $arr[$prop]['name'] ?? null;
679680
$this->locationSlug = $arr[$prop]['slug'] ?? null;
680681
$this->locationAddressJson = $arr[$prop]['address_json'] ?? null;
@@ -853,6 +854,9 @@ protected function initPropertiesCustom($value, $prop, $arr)
853854
private static function setCarouselMedia($mediaArray, $carouselArray, $instance)
854855
{
855856
$carouselMedia = new CarouselMedia();
857+
if(isset($carouselArray['id'])) {
858+
$carouselMedia->setId($carouselArray['id']);
859+
}
856860
if(isset($carouselArray['type'])) {
857861
$carouselMedia->setType($carouselArray['type']);
858862

0 commit comments

Comments
 (0)