I want to build an android app to download instagram images and videos and igtvs.So I can download pictures easily without need to access token,but for downloading videos I have to have access token to use instagram api and finally I have no idea about downloading igtv. I uploaded an igtv video on my page(my app is in sandbox mode,but I'm admin) and instagram responds that "media url is not valid".
Oh It's very easy after one week struggle with Instagram API and searching for find a way!
Get html content of the page and with regex find the download link:
<meta property="og:video" content="video_link" />
And this regex will be so useful:
String getVideoUrl(String content) {
String videoUrl = null;
String regex = "<meta property=\"og:video\" content=\"(.*?)\" />";
Pattern p = Pattern.compile(regex, Pattern.MULTILINE);
Matcher m = p.matcher(content);
if (m.find()) {
videoUrl = m.group(1);
}
return videoUrl;
}
This code will be useful for downloading video and IGTV too. In addition,to download images this one worked for me:
regex = "<meta property=\"og:image\" content=\"(.*?)\"";