@@ -54,17 +54,27 @@ protected function getData($url)
5454        ]);
5555
5656        $ raw_instagram_html  = curl_exec ($ ch );
57+         $ http_code  = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
5758
5859        $ error_code  = curl_errno ($ ch );
5960        $ error  = $ error_code  != 0  ? (': # '  . $ error_code  . ' -  '  . curl_error ($ ch )) : '' ;
6061
62+         if  (!$ error  && $ http_code  != 200 )
63+         {
64+             $ error  = ': HTTP  '  . $ http_code  . ($ http_code  == 404  ? ' - Not Found '  : '' );
65+             $ raw_instagram_html  = null ;
66+         }
67+ 
6168        curl_close ($ ch );
6269
6370        if  (!$ raw_instagram_html )
6471            return  ['errors '  => [['code '  => 0 , 'message '  => 'Unable to retrieve instagram post '  . $ error ]], 'url '  => $ url ];
6572
6673        preg_match ('/window\._sharedData = (.*);<\/script>/ ' , $ raw_instagram_html , $ matches , PREG_OFFSET_CAPTURE , 0 );
6774
75+         if  (!$ matches  || count ($ matches ) < 2  || count ($ matches [1 ]) < 1 )
76+             return  ['errors '  => [['code '  => 0 , 'message '  => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data. ' ]], 'url '  => $ url ];
77+ 
6878        $ post  = json_decode ($ matches [1 ][0 ], true );
6979
7080        if  (!$ post
@@ -74,7 +84,7 @@ protected function getData($url)
7484            || !isset ($ post ['entry_data ' ]['PostPage ' ][0 ]['graphql ' ])
7585            || !isset ($ post ['entry_data ' ]['PostPage ' ][0 ]['graphql ' ]['shortcode_media ' ]))
7686        {
77-             return  ['errors '  => [['code '  => 0 , 'message '  => 'Unable to retrieve instagram post ' ]], 'url '  => $ url ];
87+             return  ['errors '  => [['code '  => 0 , 'message '  => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data.  ' ]], 'url '  => $ url ];
7888        }
7989
8090        // Instagram Post or Inner Post (as you like) 
0 commit comments