There is such a piece of code:

($mediaId = '1278763660642187302_215594189'; $dannie = (json_encode($i->mediaInfo($mediaId))); var_dump($dannie);) 

Which returns me to: string(4520) "{"auto_load_more_enabled":true,"items":[{"taken_at":1466660529,"pk":1.2787636606422e+18,"id":"1278763660642187302_215594189","device_timestamp":1466660289,"media_type":1,"code":"BG_FMYwQXgm","client_cache_key":"MTI3ODc2MzY2MDY0MjE4NzMwMg==.2","filter_type":114,"image_versions2" so on. You need to get id from all of this and add it to your string(4520) "{"auto_load_more_enabled":true,"items":[{"taken_at":1466660529,"pk":1.2787636606422e+18,"id":"1278763660642187302_215594189","device_timestamp":1466660289,"media_type":1,"code":"BG_FMYwQXgm","client_cache_key":"MTI3ODc2MzY2MDY0MjE4NzMwMg==.2","filter_type":114,"image_versions2" . fought with it all night, tried to use regular expressions, but it still does not work.

Update

Here is what is written in the function that we call:

 public function mediaInfo($mediaId) { $data = json_encode([ '_uuid' => $this->uuid, '_uid' => $this->username_id, '_csrftoken' => $this->token, 'media_id' => $mediaId, ]); return $this->request("media/$mediaId/info/", $this->generateSignature($data))[1]; } ) 

This is how we address it:

 var_dump($i ->mediaInfo($mediaId)); 

In this case, we get the following:

 array(5) { ["auto_load_more_enabled"]=> bool(true) ["items"]=> array(1) { [0]=> array(23) { ["taken_at"]=> int(1466660529) ["pk"]=> float(1.2787636606422E+18) ["id"]=> string(29) "1278763660642187302_215594189" ["device_timestamp"]=> int(1466660289) ["media_type"]=> int(1) ["code"]=> string(11) "BG_FMYwQXgm" ["client_cache_key"]=> string(30) "MTI3ODc2MzY2MDY0MjE4NzMwMg==.2" ["filter_type"]=> int(114) ["image_versions2"]=> array(1) { ["candidates"]=> array(7) { [0]=> array(3) { ["url"]=> string(150) 

PS With the help of your code I got a NULL result.

    2 answers 2

    Use json_decode

     $data = json_decode($text, true); $id = $data['items'][0]['id']; 

    Most likely, $ data ['items'] is an array with several elements. Then for each, you can get an id using foreach ($data['items'] as $item) { echo $item['id']; } foreach ($data['items'] as $item) { echo $item['id']; } And it's not clear why json_encode is used. Why not to work immediately with the received object?

      Here is what is written in the function that we call: public function mediaInfo ($ mediaId) {$ data = json_encode (['_uuid' => $ this-> uuid, '_uid' => $ this-> username_id, '_csrftoken' = > $ this-> token, 'media_id' => $ mediaId,]);

        return $this->request("media/$mediaId/info/", $this->generateSignature($data))[1]; 

      }) This is how we refer to it: var_dump ($ i -> mediaInfo ($ mediaId)); In this case, we get the following: array (5) {["auto_load_more_enabled"] => bool (true) ["items"] => array (1) {[0] => array (23) {["taken_at"] => int (1466660529) ["pk"] => float (1.2787636606422E + 18) ["id"] => string (29) "1278763660642187302_215594189" ["device_timestamp"] => int (1466660289) ["media_type"] => int (1) ["code"] => string (11) "BG_FMYwQXgm" ["client_cache_key"] => string (30) "MTI3ODc2MzY2MDY0MjE4NzMwMg ==. 2" ["filter_type"] => int (114) [ "image_versions2"] => array (1) {["candidates"] => array (7) {[0] => array (3) {["url"] => string (150) PS With the help of your code received as a result, NULL.

      • So what? What is the answer to the question? - ilyaplot