@@ -1375,7 +1375,8 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
1375
1375
}
1376
1376
if ($ response ->code !== static ::HTTP_OK ) {
1377
1377
throw new InstagramException ('Response code is ' . $ response ->code . ': ' . static ::httpCodeToString ($ response ->code ) . '. ' .
1378
- 'Something went wrong. Please report issue. ' , $ response ->code , static ::getErrorBody ($ response ->body ));
1378
+ 'Something went wrong. Please report issue. Body: ' . static ::getErrorBody ($ response ->body )
1379
+ , $ response ->code , static ::getErrorBody ($ response ->body ));
1379
1380
}
1380
1381
1381
1382
$ this ->parseCookies ($ response ->headers );
@@ -1387,16 +1388,21 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
1387
1388
}
1388
1389
$ rootKey = array_key_exists ('graphql ' , $ arr ) ? 'graphql ' : 'data ' ;
1389
1390
1390
- if (empty ($ arr [$ rootKey ]['hashtag ' ][ ' edge_hashtag_to_media ' ][ ' count ' ])) {
1391
+ if (empty ($ arr [$ rootKey ]['media_count ' ])) {
1391
1392
return [];
1392
1393
}
1393
1394
1394
- $ nodes = $ arr [$ rootKey ]['hashtag ' ]['edge_hashtag_to_media ' ]['edges ' ];
1395
+ $ payload = $ arr [$ rootKey ]['recent ' ]['sections ' ];
1396
+ $ nodes = array ();
1397
+ foreach ($ payload as $ p ){
1398
+ $ nodes = array_merge ($ nodes ,$ p ['layout_content ' ]['medias ' ]);
1399
+ }
1400
+
1395
1401
foreach ($ nodes as $ mediaArray ) {
1396
1402
if ($ index === $ count ) {
1397
1403
return $ medias ;
1398
1404
}
1399
- $ media = Media::create ($ mediaArray ['node ' ]);
1405
+ $ media = Media::create ($ mediaArray ['media ' ]);
1400
1406
if (in_array ($ media ->getId (), $ mediaIds )) {
1401
1407
return $ medias ;
1402
1408
}
@@ -1410,8 +1416,8 @@ public function getMediasByTag($tag, $count = 12, $maxId = '', $minTimestamp = n
1410
1416
if (empty ($ nodes )) {
1411
1417
return $ medias ;
1412
1418
}
1413
- $ maxId = $ arr [$ rootKey ]['hashtag ' ]['edge_hashtag_to_media ' ]['page_info ' ]['end_cursor ' ];
1414
- $ hasNextPage = $ arr [$ rootKey ]['hashtag ' ]['edge_hashtag_to_media ' ]['page_info ' ]['has_next_page ' ];
1419
+ $ maxId = $ arr [$ rootKey ]['recent ' ][ ' next_max_id ' ]; // $arr[$rootKey][' hashtag']['edge_hashtag_to_media']['page_info']['end_cursor'];
1420
+ $ hasNextPage = $ arr [$ rootKey ]['recent ' ][ ' more_available ' ]; // $arr[$rootKey][' hashtag']['edge_hashtag_to_media']['page_info']['has_next_page'];
1415
1421
}
1416
1422
return $ medias ;
1417
1423
}
@@ -1443,8 +1449,9 @@ public function getPaginateMediasByTag($tag, $maxId = '')
1443
1449
}
1444
1450
1445
1451
if ($ response ->code !== static ::HTTP_OK ) {
1446
- throw new InstagramException ('Response code is ' . $ response ->code . ': ' . static ::httpCodeToString ($ response ->code ) . '. ' .
1447
- 'Something went wrong. Please report issue. ' , $ response ->code , static ::getErrorBody ($ response ->body ));
1452
+ throw new InstagramException ('Response code is ' . $ response ->code . ': ' . static ::httpCodeToString ($ response ->code ) . '. ' .
1453
+ 'Something went wrong. Please report issue. Body: ' . static ::getErrorBody ($ response ->body )
1454
+ , $ response ->code , static ::getErrorBody ($ response ->body ));
1448
1455
}
1449
1456
1450
1457
$ this ->parseCookies ($ response ->headers );
@@ -1454,24 +1461,29 @@ public function getPaginateMediasByTag($tag, $maxId = '')
1454
1461
if (!is_array ($ arr )) {
1455
1462
throw new InstagramException ('Response decoding failed. Returned data corrupted or this library outdated. Please report issue ' );
1456
1463
}
1464
+ $ rootKey = array_key_exists ('graphql ' , $ arr ) ? 'graphql ' : 'data ' ;
1457
1465
1458
- if (empty ($ arr [' data ' ]['hashtag ' ][ ' edge_hashtag_to_media ' ][ ' count ' ])) {
1466
+ if (empty ($ arr [$ rootKey ]['media_count ' ])) {
1459
1467
return $ toReturn ;
1460
1468
}
1461
1469
1462
- $ nodes = $ arr ['data ' ]['hashtag ' ]['edge_hashtag_to_media ' ]['edges ' ];
1470
+ $ payload = $ arr [$ rootKey ]['recent ' ]['sections ' ];
1471
+ $ nodes = array ();
1472
+ foreach ($ payload as $ p ){
1473
+ $ nodes = array_merge ($ nodes ,$ p ['layout_content ' ]['medias ' ]);
1474
+ }
1463
1475
1464
1476
if (empty ($ nodes )) {
1465
1477
return $ toReturn ;
1466
1478
}
1467
1479
1468
1480
foreach ($ nodes as $ mediaArray ) {
1469
- $ medias [] = Media::create ($ mediaArray ['node ' ]);
1481
+ $ medias [] = Media::create ($ mediaArray ['media ' ]);
1470
1482
}
1471
1483
1472
- $ maxId = $ arr ['data ' ]['hashtag ' ]['edge_hashtag_to_media ' ]['page_info ' ]['end_cursor ' ];
1473
- $ hasNextPage = $ arr ['graphql ' ]['hashtag ' ]['edge_hashtag_to_media ' ]['page_info ' ]['has_next_page ' ];
1474
- $ count = $ arr ['data ' ]['hashtag ' ]['edge_hashtag_to_media ' ]['count ' ];
1484
+ $ maxId = $ arr [$ rootKey ][ ' recent ' ][ ' next_max_id ' ]; // $arr[ 'data']['hashtag']['edge_hashtag_to_media']['page_info']['end_cursor'];
1485
+ $ hasNextPage = $ arr [$ rootKey ][ ' recent ' ][ ' more_available ' ]; // $arr[ 'graphql']['hashtag']['edge_hashtag_to_media']['page_info']['has_next_page'];
1486
+ $ count = $ arr [$ rootKey ][ ' media_count ' ]; // $arr[ 'data']['hashtag']['edge_hashtag_to_media']['count'];
1475
1487
1476
1488
$ toReturn = [
1477
1489
'medias ' => $ medias ,
@@ -1572,16 +1584,30 @@ public function getCurrentTopMediasByTagName($tagName)
1572
1584
throw new InstagramNotFoundException ('Account with given username does not exist. ' );
1573
1585
}
1574
1586
if ($ response ->code !== static ::HTTP_OK ) {
1575
- throw new InstagramException ('Response code is ' . $ response ->code . ': ' . static ::httpCodeToString ($ response ->code ) . '. ' .
1576
- 'Something went wrong. Please report issue. ' );
1587
+ throw new InstagramException ('Response code is ' . $ response ->code . ': ' . static ::httpCodeToString ($ response ->code ) . '. ' .
1588
+ 'Something went wrong. Please report issue. Body: ' . static ::getErrorBody ($ response ->body )
1589
+ , $ response ->code , static ::getErrorBody ($ response ->body ));
1577
1590
}
1578
1591
1579
1592
$ this ->parseCookies ($ response ->headers );
1580
- $ jsonResponse = $ this ->decodeRawBodyToJson ($ response ->raw_body );
1593
+
1594
+ $ arr = $ this ->decodeRawBodyToJson ($ response ->raw_body );
1595
+
1596
+ if (!is_array ($ arr )) {
1597
+ throw new InstagramException ('Response decoding failed. Returned data corrupted or this library outdated. Please report issue ' );
1598
+ }
1599
+ $ rootKey = array_key_exists ('graphql ' , $ arr ) ? 'graphql ' : 'data ' ;
1600
+
1581
1601
$ medias = [];
1582
- $ nodes = (array )@$ jsonResponse ['graphql ' ]['hashtag ' ]['edge_hashtag_to_top_posts ' ]['edges ' ];
1602
+
1603
+ $ payload = $ arr [$ rootKey ]['top ' ]['sections ' ];
1604
+ $ nodes = array ();
1605
+ foreach ($ payload as $ p ){
1606
+ $ nodes = array_merge ($ nodes ,$ p ['layout_content ' ]['medias ' ]);
1607
+ }
1608
+
1583
1609
foreach ($ nodes as $ mediaArray ) {
1584
- $ medias [] = Media::create ($ mediaArray ['node ' ]);
1610
+ $ medias [] = Media::create ($ mediaArray ['media ' ]);
1585
1611
}
1586
1612
return $ medias ;
1587
1613
}
0 commit comments