diff --git a/README.md b/README.md index 4743912..0d21b4e 100644 --- a/README.md +++ b/README.md @@ -161,12 +161,12 @@ paylaşımlarını getirmek için get_user_posts('hasokeyk') yazmanız yeterlidi | Giriş Yapmış Kullanıcı Bilgisi Getirme | :heavy_check_mark: | [instagram-user-info.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-info.php) | | Giriş Yapmış Kullanıcı İstatistik Getirme | :heavy_check_mark: | [instagram-user-statistics.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-statistics.php) | | Giriş Yapmış Kullanıcının En Az Etkileşimde Olduğu Kullanıcılar | :heavy_check_mark: | [instagram-user-least-interacted-with.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-least-interacted-with.php) | -| Giriş Yapmış Kullanıcının En Çok Gördüğü Kullanıcılar | :heavy_check_mark: | [instagram-user-me-most-seen-in-feed.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-least-interacted-with.php) | -| Profil Resmi Değiştirme | :heavy_check_mark: | [instagram-user-change-profil-pic.php](https://github.com/Hasokeyk/instagram/blob/main/examples/instagram-user-change-profil-pic.php) | -| Kullanıcı Takip Etme | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/instagram-user-follow.php) | -| Kullanıcı Takipten Çıkma | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/instagram-user-follow.php) | -| Kullanıcının Kendisini Takipten Çıkma | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/instagram-user-follow.php) | -| Kullanıcı Bildirim Listesi Getirme | :heavy_check_mark: | [instagram-user-me-notification.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-me-notification.php) | +| Giriş Yapmış Kullanıcının En Çok Gördüğü Kullanıcılar | :heavy_check_mark: | [instagram-user-my-most-seen-in-feed.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-least-interacted-with.php) | +| Profil Resmi Değiştirme | :heavy_check_mark: | [instagram-user-change-profil-pic.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-change-profil-pic.php) | +| Kullanıcı Takip Etme | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-follow.php) | +| Kullanıcı Takipten Çıkma | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-follow.php) | +| Kullanıcının Kendisini Takipten Çıkma | :heavy_check_mark: | [instagram-user-follow.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-follow.php) | +| Kullanıcı Bildirim Listesi Getirme | :heavy_check_mark: | [instagram-user-my-notification.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-my-notification.php) | | Kullanıcı Mesaj İsteklerini Getirme | :heavy_check_mark: | [instagram-user-my-pending-inbox.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-my-pending-inbox.php) | | Kullanıcı Mesaj Kutusunu Getirme | :heavy_check_mark: | [instagram-user-my-inbox.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-my-inbox.php) | | Kullanıcı Takipçilerini Getirme | :heavy_check_mark: | [instagram-user-my-followers.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-my-followers.php) | @@ -177,8 +177,8 @@ paylaşımlarını getirmek için get_user_posts('hasokeyk') yazmanız yeterlidi | İşlemler | Çalışıyor | Örnek Dosya | | ------------- | ------------- | ------------- | -| Paylaşım İstatistikleri Getirme | :heavy_check_mark: | [instagram-user-get-posts-statistics.php](https://github.com/Hasokeyk/instagram/blob/main/examples/media/instagram-user-get-posts-statistics.php) | -| Görsel Paylaşma | :x: | [HAZIRLANIYOR](https://github.com/Hasokeyk/instagram/blob/main/examples/media/) | +| Paylaşım İstatistikleri Getirme | :heavy_check_mark: | [instagram-user-get-posts-statistics.php](https://github.com/Hasokeyk/instagram/blob/main/examples/statistics/instagram-user-get-posts-statistics.php) | +| Görsel Paylaşma | :heavy_check_mark: | [instagram-media-share-photo.php](https://github.com/Hasokeyk/instagram/blob/main/examples/media/instagram-media-share-photo.php) | | Video Paylaşma | :x: | [HAZIRLANIYOR](https://github.com/Hasokeyk/instagram/blob/main/examples/media/) | | Story Paylaşma | :x: | [HAZIRLANIYOR](https://github.com/Hasokeyk/instagram/blob/main/examples/media/) | | Carousel Paylaşma | :x: | [HAZIRLANIYOR](https://github.com/Hasokeyk/instagram/blob/main/examples/media/) | diff --git a/examples/media/instagram-media-share-photo.php b/examples/media/instagram-media-share-photo.php new file mode 100644 index 0000000..20beaab --- /dev/null +++ b/examples/media/instagram-media-share-photo.php @@ -0,0 +1,19 @@ +login->login(); + + if($instagram->login->login_control()){ + $image_path = (__DIR__).'/assets/a.jpg'; + $check = $instagram->medias->share_photo($image_path,'Test'); + print_r($check); + }else{ + echo 'Login Fail'; + } diff --git a/src/instagram.php b/src/instagram.php index 5ce216a..091cb42 100644 --- a/src/instagram.php +++ b/src/instagram.php @@ -4,6 +4,7 @@ require "instagram_request.php"; require "instagram_login.php"; + require "instagram_register.php"; require "instagram_user.php"; require "instagram_statistics.php"; require "instagram_upload.php"; @@ -15,6 +16,7 @@ class instagram{ public $functions = []; public $request = null; public $login = null; + public $register = null; public $user = null; public $statistics = null; public $medias = null; @@ -26,6 +28,7 @@ function __construct($username = null, $password = null){ $this->functions = (object) [ 'request' => new instagram_request($username, $password, $this->functions), 'login' => new instagram_login($username, $password, $this->functions), + 'register' => new instagram_register($username, $password, $this->functions), 'statistics' => new instagram_statistics($username, $password, $this->functions), 'user' => new instagram_user($username, $password, $this->functions), 'upload' => new instagram_upload($username, $password, $this->functions), @@ -35,6 +38,7 @@ function __construct($username = null, $password = null){ $this->request = new instagram_request($username, $password, $this->functions); $this->login = new instagram_login($username, $password, $this->functions); + $this->register = new instagram_register($username, $password, $this->functions); $this->user = new instagram_user($username, $password, $this->functions); $this->statistics = new instagram_statistics($username, $password, $this->functions); $this->upload = new instagram_upload($username, $password, $this->functions); diff --git a/src/instagram_medias.php b/src/instagram_medias.php index cea74b6..ddcd908 100644 --- a/src/instagram_medias.php +++ b/src/instagram_medias.php @@ -279,4 +279,80 @@ public function share_media_inbox($post_id = null, $username = null){ } + public function share_photo($image_path = null, $desc = null){ + + $upload_id = $this->functions->upload->get_upload_id(); + $upload_session_id = $this->functions->upload->get_upload_session_id($upload_id); + $url = 'https://i.instagram.com/rupload_igphoto/'.$upload_session_id; + + $file = file_get_contents($image_path); + $file_size = strlen($file); + + $header = [ + "Content-Type" => "application/octet-stream", + "X-Entity-Type" => "image/jpeg", + "X-Entity-Name" => $upload_session_id, + "Offset" => "0", + "X-Entity-Length" => $file_size, + "Cookie" => $this->create_cookie(), + "X-Instagram-Rupload-Params" => $this->functions->upload->rupload_params($upload_id), + ]; + + $json = $this->request($url, 'UPLOAD', ['body' => $file], $header); + $json = json_decode($json['body']); + if($json->status == 'ok'){ + $result = $this->_share_photo($upload_id, $desc); + print_r($result); + if($result->status == 'ok'){ + return true; + } + } + + return false; + + } + + private function _share_photo($upload_id = null, $desc = null){ + + $url = 'https://i.instagram.com/api/v1/media/configure/'; + $post_data = [ + "scene_capture_type" => "", + "timezone_offset" => "10800", + "_csrftoken" => "L3toHeMiinPTPxRkOST8feCLY0gIa61x", + "media_folder" => "Camera", + "source_type" => "4", + "_uid" => "44433622125", + "device_id" => $this->get_device_id(), + "_uuid" => $this->get_guid(), + "creation_logger_session_id" => "cf4fea1e-a304-44d9-af56-62914c9d728e", + "caption" => $desc, + "upload_id" => $upload_id, + "multi_sharing" => "1", + "device" => [ + "manufacturer" => "Google", + "model" => "google+Pixel+2", + "android_version" => 22, + "android_release" => "5.1.1", + ], + "edits" => [ + "crop_original_size" => [ + 640, + 480, + ], + "crop_center" => [ + 0, + -0, + ], + "crop_zoom" => 1.3333334, + ], + "extra" => [ + "source_width" => 640, + "source_height" => 480, + ], + ]; + $post_data = ['signed_body' => 'SIGNATURE.'.json_encode($post_data)]; + $json = $this->request($url, 'POST', $post_data); + return json_decode($json['body']); + + } } \ No newline at end of file diff --git a/src/instagram_register.php b/src/instagram_register.php new file mode 100644 index 0000000..8576708 --- /dev/null +++ b/src/instagram_register.php @@ -0,0 +1,94 @@ +username = $username; + $this->password = $password; + $this->functions = $functions; + } + + public function username_check($username = null){ + + $username = $username??$this->username; + + $url = 'https://i.instagram.com/api/v1/users/check_username/'; + $post_data = [ + 'username' => $username, + '_uuid' => $this->get_guid(), + ]; + $post_data = ['signed_body' => 'SIGNATURE.'.json_encode($post_data)]; + $json = $this->request($url, 'POST', $post_data); + if($json['status'] == 'ok'){ + $json = json_decode($json['body']); + } + return $json; + + } + + public function get_steps(){ + + $url = 'https://i.instagram.com/api/v1/dynamic_onboarding/get_steps/'; + $post_data = [ + 'is_secondary_account_creation' => 'true', + 'fb_connected' => 'false', + 'seen_steps' => "[]", + 'progress_state' => "prefetch", + 'fb_installed' => "false", + 'is_ci' => "false", + 'network_type' => "WIFI-UNKNOWN", + 'waterfall_id' => "97d01ad3-6555-49ac-b7f5-69da7f241367", + 'tos_accepted' => "false", + 'phone_id' => $this->get_phone_id(), + '_uuid' => $this->get_guid(), + 'guid' => $this->get_guid(), + '_csrftoken' => $this->get_csrftoken(), + 'android_id' => $this->get_device_id(), + ]; + $post_data = ['signed_body' => 'SIGNATURE.'.json_encode($post_data)]; + $json = $this->request($url, 'POST', $post_data); + if($json['status'] == 'ok'){ + $json = json_decode($json['body']); + } + return $json; + + } + + public function register($username = null, $password = null){ + + $username = $username??$this->username; + $password = $password??$this->password; + + $url = 'https://i.instagram.com/api/v1/dynamic_onboarding/get_steps/'; + $post_data = [ + 'is_secondary_account_creation' => 'true', + 'fb_connected' => 'false', + 'seen_steps' => "[]", + 'progress_state' => "prefetch", + 'fb_installed' => "false", + 'is_ci' => "false", + 'network_type' => "WIFI-UNKNOWN", + 'waterfall_id' => "97d01ad3-6555-49ac-b7f5-69da7f241367", + 'tos_accepted' => "false", + 'phone_id' => $this->get_phone_id(), + '_uuid' => $this->get_guid(), + 'guid' => $this->get_guid(), + '_csrftoken' => $this->get_csrftoken(), + 'android_id' => $this->get_device_id(), + ]; + $post_data = ['signed_body' => 'SIGNATURE.'.json_encode($post_data)]; + $json = $this->request($url, 'POST', $post_data); + if($json['status'] == 'ok'){ + $json = json_decode($json['body']); + } + return $json; + + } + + } \ No newline at end of file diff --git a/src/instagram_upload.php b/src/instagram_upload.php index febba95..b33f589 100644 --- a/src/instagram_upload.php +++ b/src/instagram_upload.php @@ -70,7 +70,7 @@ public function rupload_params($upload_id) { "upload_id" => $upload_id, "xsharing_user_ids" => "[]", "image_compression" => json_encode($image_comp), - "original_photo_pdq_hash" => ""//todo add PDQ Hashing algorithm + "original_photo_pdq_hash" => "" ]; return json_encode($data); } diff --git a/src/instagram_user.php b/src/instagram_user.php index c0448ad..9f45721 100644 --- a/src/instagram_user.php +++ b/src/instagram_user.php @@ -155,13 +155,13 @@ public function get_user_info_by_username($username = null){ public function get_multi_user_friendship_show($user_ids = []){ if($user_ids != null){ - $user_ids = implode(',',$user_ids); - $url = 'https://i.instagram.com/api/v1/friendships/show_many/'; + $user_ids = implode(',', $user_ids); + $url = 'https://i.instagram.com/api/v1/friendships/show_many/'; $post_data = [ - 'user_ids' => $user_ids + 'user_ids' => $user_ids, ]; - $json = $this->request($url,'POST',$post_data); - $json = json_decode($json['body']); + $json = $this->request($url, 'POST', $post_data); + $json = json_decode($json['body']); return $json; } @@ -592,6 +592,36 @@ public function get_friendships_status_by_username($username = null){ } + public function get_former_usernames($username = null){ + + $username = $username??$this->username; + $user_id = $this->get_user_id($username); + $url = 'https://i.instagram.com/api/v1/users/'.$user_id.'/former_usernames/'; + $json = $this->request($url, 'GET'); + $json = json_decode($json['body']); + if(isset($json->status) and $json->status == 'ok'){ + return $json; + } + return false; + + } + + /* + public function get_accounts_with_shared_followers($username = null){ + + $username = $username??$this->username; + $user_id = $this->get_user_id($username); + $url = 'https://i.instagram.com/api/v1/users/'.$user_id.'/accounts_with_shared_followers/'; + $json = $this->request($url, 'POST'); + $json = json_decode($json['body']); + if(isset($json->status) and $json->status == 'ok'){ + return $json; + } + return false; + + } + */ + private function generate_client_context(){ return (round(microtime(true) * 1000) << 22 | random_int(PHP_INT_MIN, PHP_INT_MAX) & 4194303) & PHP_INT_MAX; }