threads.net web sitesinden Instagram kullanıcılarının bilgilerini ve gönderilerini almak için kullanabileceğiniz bir PHP API'si paylaşmak istiyorum. Bu API sayesinde kullanıcı adıyla birlikte kullanıcının bilgilerini ve gönderilerini elde edebilirsiniz.
API'nin kullanımı oldukça basittir. Sadece kullanıcı adını göndererek API'yi çalıştırabilirsiniz. API kullanıcının hesap bilgilerini ve en son gönderilerini getirecek ve JSON formatında döndürecektir.
Bilgilendirme : @yusuf68700; adlı arkadaşımızın Threads UserINFO konusunda paylaştığı kodu kullandım getInfo fonksiyonunda ve kod gayet stabil çalışmakta "Yusuf" hocama da ayrıca teşekkürlerimi iletmekteyim.
İyi kullanımlar..
<?php function parseInfoAndControl($data) { $info = array(); $decodedData = json_decode($data, true); if (isset($decodedData['data']) && $decodedData['data']) { $userData = $decodedData['data']['userData']['user']; if ($userData['is_private'] == true) { $info['privateStatus'] = 'This account is private.'; } else { $info['privateStatus'] = 'This account not private.'; } $info['username'] = $userData['username']; if ($userData['is_verified'] == true) { $info['isVerified'] = 'This account is verified.'; } else { $info['isVerified'] = 'This account not verified.'; } $info['biography'] = $userData['biography']; $info['followerCount'] = $userData['follower_count']; $info['bioLinks'] = $userData['bio_links']; $info['threadsId'] = $userData['pk']; $info['fullName'] = $userData['full_name']; $hdProfilePics = $userData['hd_profile_pic_versions']; $maxSizePic = null; foreach ($hdProfilePics as $pic) { if (!$maxSizePic || ($pic['width'] > $maxSizePic['width'] && $pic['height'] > $maxSizePic['height'])) { $maxSizePic = $pic; } } if ($maxSizePic) { $info['maxSizePicture'] = $maxSizePic['url']; } else { $info['maxSizePicture'] = null; } } return $info; } function postsParse($data) { $textCaptions = array(); $decodedData = json_decode($data, true); if (strpos("ERROR", $data) !== false) { $textCaptions['error'] = "Error"; return $textCaptions; exit; } if (isset($decodedData['data']) && $decodedData['data']) { $postData = $decodedData['data']['mediaData']['threads']; foreach ($postData as $allPosts) { $postsText = $allPosts["thread_items"][0]["post"]; if (isset($postsText["caption"]["text"])) { $postsCaption = $postsText["caption"]["text"]; array_push($textCaptions, $postsCaption); } } } return $textCaptions; } function getInfo($id = "") { if (empty($id)) { echo "Please enter the user ID"; exit; } $url = 'https://www.threads.net/api/graphql'; $headers = array( 'Host: www.threads.net', 'X-Ig-App-Id: 238260118697367', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 OPR/99.0.0.0', 'X-Fb-Friendly-Name: BarcelonaPostLikersDialogQuery', 'X-Fb-Lsd: RJ2eSzz0Tju308lXT_bGZ6', 'Content-Type: application/x-www-form-urlencoded', 'X-Asbd-Id: 129477', 'Accept: */*', 'Origin: https://www.threads.net', 'Sec-Fetch-Site: same-origin', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Dest: empty', 'Referer: https://www.threads.net', 'Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7' ); $data = array( 'lsd' => 'RJ2eSzz0Tju308lXT_bGZ6', 'variables' => '{"userID":"' . $id . '"}', 'doc_id' => '23996318473300828' ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close($ch); return $response; } function getPosts($id = "") { if (empty($id)) { echo "Please enter the user ID"; exit; } $url = 'https://www.threads.net/api/graphql'; $headers = array( 'Host: www.threads.net', 'X-Ig-App-Id: 238260118697367', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 OPR/99.0.0.0', 'X-Fb-Friendly-Name: BarcelonaProfileThreadsTabQuery', 'X-Fb-Lsd: RJ2eSzz0Tju308lXT_bGZ6', 'Content-Type: application/x-www-form-urlencoded', 'X-Asbd-Id: 129477', 'Accept: */*', 'Origin: https://www.threads.net', 'Sec-Fetch-Site: same-origin', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Dest: empty', 'Referer: https://www.threads.net', 'Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7' ); $data = array( 'lsd' => 'RJ2eSzz0Tju308lXT_bGZ6', 'variables' => '{"userID":"' . $id . '"}', 'doc_id' => '6451898791498605' ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close($ch); return $response; } if (isset($_GET["username"])) { $user = strip_tags(htmlspecialchars($_GET["username"])); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.threads.net/" . $user); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Host: www.threads.net', 'X-Ig-App-Id: 238260118697367', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 OPR/99.0.0.0', 'X-Asbd-Id: 129477', 'Accept: */*', 'Origin: https://www.threads.net', 'Sec-Fetch-Site: same-origin', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Dest: empty', 'Referer: https://www.threads.net', 'Accept-Language: tr' )); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); $result = curl_exec($ch); curl_close($ch); $pattern = '/{"user_id":"(\d+)"}/'; if (preg_match($pattern, $result, $matches)) { $userId = $matches[1]; $response = getInfo($userId); $responseInfo = parseInfoAndControl($response); $posts = getPosts($userId); $parse = postsParse($posts); echo json_encode(array( 'status' => true, 'message' => 'Person info successfully scraped.', 'data' => $responseInfo, 'posts' => $parse )); exit; } else { echo json_encode(array( 'status' => false, 'message' => 'Person info not found.' )); exit; } } else { echo json_encode(array( 'status' => false, 'message' => 'Please enter the username.' )); exit; }