php - Instagram 上的 JSON 文件 __a=1 给我 html?
问题描述
我要指出的是我这周开始学习php,所以代码会有点狗屎,但现在它已经足够了,它是真诚的
我创建了这个脚本,该脚本使用该 URL 的 file_get_contents ()转到https://www.instagram.com/USERNAME/?__a=1 (此地址有一个 JSON 文件),应该将 JSON 文件返回给我,并且本地发生这种情况!在本地完美运行!但是在我的域上托管脚本无法正常工作,即 file_get_contents () 给了我一个奇怪的 html 页面,这在我给它的链接中绝对找不到!而且我不明白为什么以及到期的原因!instagram 注意到我已阅读数据并将我重定向到另一个页面?我错过了代码中的某些内容吗?我做错了吗?我不知道,我请你帮忙!我还尝试读取也位于 cURL 但无事可做的文件
我还想过重做 JS 中的所有代码,希望不会发生同样的事情,但我不想从头再来,也许会发现自己的代码给了我同样的结果!
我在这里附上代码
<?php
$commentiPost;
$likePost;
$postData;
$image;
$urlprofilo;
$followers;
$username;
$follow;
$like;
$commenti;
function getMediaByUsername($count) {
global $image;
global $commentiPost;
global $likePost;
global $urlprofilo;
global $followers;
global $username;
global $follow;
global $postData;
global $like;
global $commenti;
$uname = htmlspecialchars($_GET["name"]);
$username = strtolower(str_replace(' ','_',$uname));
$url = "https://www.instagram.com/".$username."/?__a=1";
$userinfo = file_get_contents($url);
$userdata = json_decode($userinfo,true);
$user = $userdata['graphql']['user'];
$iteration_url = $url;
if(!empty($user)){
$followers = $user['edge_followed_by']['count'];
$follow = $user['edge_follow']['count'];
$fullname = $user['full_name'];
$username = $user['username'];
$profilepic = $user['profile_pic_url'];
$profilepic = (explode("/",$profilepic));
$urlprofilo = "https://scontent-frt3-1.cdninstagram.com/v/t51.2885-19/s150x150/$profilepic[6]";
$limit = $count;
$tryNext = true;
$found = 0;
while ($tryNext) {
$tryNext = false;
$remote = file_get_contents( $iteration_url );
$response = $remote;
if ($response === false) {
return false;
}
$data = json_decode($response, true);
if ( $data === null) {
return false;
}
$media = $data['graphql']['user']['edge_owner_to_timeline_media'];
foreach ( $media['edges'] as $index => $node ) {
if ( $found + $index < $limit ) {
if (isset($node['node']['is_video']) && $node['node']['is_video'] == true) {
$type = 'video';
} else {
$type = 'image';
}
$like = $like + $node['node']['edge_liked_by']['count'];
$commenti = $commenti + $node['node']['edge_media_to_comment']['count'];
$image[] = array( "<a href=".$node['node']['display_url'].">
<img src=".$node['node']['display_url']." alt="." />
<h3>Like: </strong>".$node['node']['edge_liked_by']['count']."</strong> Commenti: <strong>".$node['node']['edge_media_to_comment']['count']."</strong></h3>
</a>");
$postData[] = array(" '".gmdate("d-m-Y",$node['node']['taken_at_timestamp'])."',");
$likePost[] = array(" ".$node['node']['edge_liked_by']['count'].",");
$commentiPost[] = array(" ".$node['node']['edge_media_to_comment']['count'].",");
}
}
$found += count($media['edges']);
if ( $media['page_info']['has_next_page'] && $found < $limit ) {
$iteration_url = $url . '&max_id=' . $media['page_info']['end_cursor'];
$tryNext = true;
}
}
} else{
}
}
getMediaByUsername( 12);
if(isset($image))
{
$postTot = count($image);
}
else {
$postTot = 0;
}
if($postTot > 0 and $followers > 0){
$ER = round(((($like + $commenti)/$postTot)/$followers)*100, 1);
}
else {
$ER = 0;
}
?>
解决方案
推荐阅读
- mysql - 这两个是不同的 ```RLIKE ^[^aeiou]``` 和 ```NOT RLIKE ^[aeiou]```?
- ruby-on-rails - 验证给我不正确的结果
- php - 如何使用 html 'id' 属性访问 php 页面中的表单详细信息
- android - 弹出菜单在 Android 中无法按预期工作
- graphql - 如何在 apollo-client 中使用枚举?
- jaws-screen-reader - 为什么 JAWS 不阅读整个句子?
- ios - 将 UI 图像定位在 UI 标签的文本“中间”
- javascript - 检索 React.js 元素的 ID
- angular - 如何循环遍历 html 中的 Set
- scala - 如何在 Scala Dataframe 中显示分组数据