PHP 解决方案
您可以在某处添加它,它会从用户那里提取 12 个最新的帖子,并以数组的形式返回照片的链接。
这是一个实现
function getPosts($profile) {
$base = "https://instagram.com/";
$end = "/?__a=1";
$ls = array();
$content = file_get_contents($base.$profile.$end);
if (strpos($content, "is_private\":false") !== false) {
return array(true, array());
}
$split = "config_height\":320},{\"src\":\"";
while (strpos($content, $split) !== false) {
$part = @explode($split, $content, 2)[1];
$p = @explode("\"", $part, 2)[0];
$content = str_replace($split.$p, "", $content);
array_push($ls, $p);
}
return array(false, $ls);
}
$x = getPosts("najemi.cz");
$isPrivate = $x[0];
$posts = $x[1]
if ($isPrivate) {
echo "Sorry, this account is private";
}else{
foreach($posts as $post) {
echo "<img src=\"$post\">";
}
}
这将在 HTML 中用于显示一个帐户的 12 个最新帖子。您可以通过添加和删除显示的内容来根据需要定制它,但除此之外,可以使用任何存在的用户名调用该函数。
使用 AJAX 的 javascript 解决方案
这个解决方案需要访问一个可以返回结果的 php 文件
Javascript 如下
function display(array1) {
array1.forEach(element => console.log(element));
}
var username = "najemi.cz";
$.ajax({
url: "./getPosts.php?p=" + username,
type: "GET",
success: function(data) {
display(data.split("\n"));
},
error: function (response) {
console.log('ERROR!', response);
}
});
名为“getPosts.php”的 php 文件将包含:
<?php
function getPosts($profile) {
$base = "https://instagram.com/";
$end = "/?__a=1";
$ls = array();
$content = file_get_contents($base.$profile.$end);
if (strpos($content, "is_private\":false") !== false) {
return array(true, array());
}
$split = "config_height\":320},{\"src\":\"";
while (strpos($content, $split) !== false) {
$part = @explode($split, $content, 2)[1];
$p = @explode("\"", $part, 2)[0];
$content = str_replace($split.$p, "", $content);
array_push($ls, $p);
}
return array(false, $ls);
}
if(isset($_GET['p'])){$p = $_GET['p'];}
$x = getPosts($p);
$isPrivate = $x[0];
$posts = $x[1]
if ($isPrivate) {
echo "Sorry, this account is private";
}else{
foreach($posts as $post) {
echo "$post\n";
}
}
?>