2020/09/20

不透過IG API Key get images comment

客戶網站需要連動IG發文功能,API申請太麻煩,只好自幹了

IG再網頁執行時透過js取得到JSON格式的資料 

程式碼如下:

 
        $.ajax({
            url: 'https://www.instagram.com/cristiano/',
            success: function (response) {
                var p = $.parseHTML(response, true);
                var v = JSON.parse($(p).filter('script')[4].innerHTML.replace('window._sharedData =', '').replace(';', '')).entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges;
                for (var i = 0; i < 6; i++) {
                    var node = v[i].node;
                    var image = node.display_url;
                    var shortUrl = node.shortcode;
                    console.log(image);
                }
            }
        });