I use mgp25/Instagram-API
release ^5.0
stable version.
I need to get all medias of the user's story.
I have this code:
$user = 'instagram';
$userId = $ig->people->getUserIdForName($user);
$feedId = $ig->highlight->getUserFeed($userId)->getTray()[0]->getId();
var_dump( $ig->story->getReelsMediaFeed($feedId)->getReels() );
Result (data is in the _objectData
private method):
object(InstagramAPI\Response\Model\UnpredictableKeys\ReelUnpredictableContainer)#1453 (4) {
["_type":protected]=>
string(33) "\InstagramAPI\Response\Model\Reel"
["_cache":protected]=>
NULL
["_compiledPropertyMapLink":"LazyJsonMapper\LazyJsonMapper":private]=>
&array(0) {
}
["_objectData":"LazyJsonMapper\LazyJsonMapper":private]=>
array(1) {
["highlight:17907400474216512"]=>
array(13) {
["id"]=>
string(27) "highlight:17907400474216512"
["latest_reel_media"]=>
int(1520611200)
["seen"]=>
NULL
:
:
I try this code:
var_dump( $ig->story->getReelsMediaFeed($feedId)->getReels()[$feedId] );
I get this error:
Fatal error: Uncaught Error: Cannot use object of type InstagramAPI\Response\Model\UnpredictableKeys\ReelUnpredictableContainer as array in...
And also I try this code:
var_dump( $ig->highlight->getUserFeed($userId)->getTray()[0]->getItems() );
But return NULL
.
I can use jsonSerialize()
or same methods:
var_dump( $ig->story->getReelsMediaFeed($feedId)->getReels()->jsonSerialize()->$feedId );
But I don't like it, and this is a funny way that will disappear as the class and form of the structure also disappear.
What's your standard solution?
From looking at the source code, you want to use the getData()
method of InstagramAPI\Response\Model\UnpredictableKeys\ReelUnpredictableContainer
$reels = $ig->story->getReelsMediaFeed($feedId)->getReels()->getData();
The getData()
method (from CoreUnpredictableContainer
) converts the data into an instance of the $_type
property.
$reels
is now an instance of InstagramAPI\Response\Model\Reel
. It's unclear what data you want from that but the API is defined pretty well in the class itself, eg
$items = $reels->getItems();
$location = $reels->getLocation();
// etc