From c0173e76711d474e2d470a676932caf921ea0dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Y=C3=BCksektepe?= Date: Thu, 12 Aug 2021 00:51:57 +0300 Subject: [PATCH] 1.0.19 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - İki adımlı giriş işlemi eklendi. --- README.md | 46 ++++++- composer.json | 2 +- .../user/instagram-user-two-factor-login.php | 34 ++++++ src/instagram_login.php | 115 ++++++++---------- 4 files changed, 134 insertions(+), 63 deletions(-) create mode 100644 examples/user/instagram-user-two-factor-login.php diff --git a/README.md b/README.md index a7327a9..6f56082 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Lütfen burayı dikkatle okunuyun. ## Örnek Kodlar -# Login işlemi +# Login/Giriş işlemi Her işlemden önce kullanıcı girişi yapmalısınız. 1 Kere giriş yaptıktan sonra sistem önbelleğe alacaktır ve bundan sonraki işlemleriniz daha hızlı bir şekilde çalışacaktır. @@ -120,6 +120,49 @@ sonraki işlemleriniz daha hızlı bir şekilde çalışacaktır. ``` +# İki Adımlı Login/Giriş işlemi + +Instagrama ilk giriş denemenizde 2 adımlı doğrulama açıksa size bir kod gelecektir. Kodu ekranda çıkan inputa girip "Login" butonuna basarsanız giriş işleminiz otomatik olarak tamamlanacaktır. +Bir dahaki girişlerde eğer ipniz değişmediyse kod sormadan giriş yapabilirsiniz. + +```php +login->two_factor_login($code, $token); + print_r($two_factor_login); + }else{ + $login = $instagram->login->login(); + if(isset($login->two_factor_identifier) and !empty($login->two_factor_identifier)){ + echo << + + + + + END; + } + else if($instagram->login->login_control()){ + echo 'Login Success'; + } + else{ + echo 'Login Fail'; + } + } + +``` + # Kullanıcı Paylaşımlarını Getirme Aşağıdaki kodları çalıştırğınızda giriş yaptığınız kullanıcının son 50 paylaşımını getireceksiniz. Başka birinin @@ -158,6 +201,7 @@ paylaşımlarını getirmek için get_user_posts('hasokeyk') yazmanız yeterlidi | İşlemler | Çalışıyor | Örnek Dosya | | ------------- | ------------- | ------------- | | Kullanıcı Girişi | :heavy_check_mark: | [instagram-user-login.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-login.php) | +| iki Adımlı Kullanıcı Girişi | :heavy_check_mark: | [iinstagram-user-two-factor-login.php](https://github.com/Hasokeyk/instagram/blob/main/examples/user/instagram-user-two-factor-login.php) | | 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) | diff --git a/composer.json b/composer.json index ebd7977..8cca6e2 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "minimum-stability": "stable", "require": { "guzzlehttp/guzzle":"^7.0.1", - "php": ">=7.0.0" + "php": "^>=7.4" }, "autoload": { "files": ["src/instagram.php"] diff --git a/examples/user/instagram-user-two-factor-login.php b/examples/user/instagram-user-two-factor-login.php new file mode 100644 index 0000000..1a78646 --- /dev/null +++ b/examples/user/instagram-user-two-factor-login.php @@ -0,0 +1,34 @@ +login->two_factor_login($code, $token); + print_r($two_factor_login); + }else{ + $login = $instagram->login->login(); + if(isset($login->two_factor_identifier) and !empty($login->two_factor_identifier)){ + echo << + + + + + END; + } + else if($instagram->login->login_control()){ + echo 'Login Success'; + } + else{ + echo 'Login Fail'; + } + } \ No newline at end of file diff --git a/src/instagram_login.php b/src/instagram_login.php index 98891d8..d6e0707 100644 --- a/src/instagram_login.php +++ b/src/instagram_login.php @@ -14,59 +14,10 @@ function __construct($username, $password, $functions = null){ $this->functions = $functions; } - public function login2($username = null, $password = null){ - - $username = $username??$this->username; - $password = $password??$this->password; - $password = $this->encrypt($password); - $this->username = $username; - - $url = 'https://i.instagram.com/api/v1/accounts/login/'; - - $post_data = [ - 'phone_id' => "832f3947-2366-42c7-a49e-88136c36f7ad", - 'enc_password' => $password, - '_csrftoken' => 'YBck6oCPqG3e2YtLRxeiebBfVQawQm04', - 'username' => $username, - 'adid' => "f5904e04-349a-48ca-8516-8555ae99660c", - 'guid' => "f1c270c3-8663-40ef-8612-3dc8853b3459", - 'device_id' => "android-daa21d4b02905ea0", - 'google_tokens' => '[]', - 'login_attempt_count' => '0', - ]; - $post_data = ['signed_body' => (string) 'SIGNATURE.{"username":"hayatikodla"}']; - - $header = [ - 'User-Agent' => 'Instagram 177.0.0.30.119 Android (22/5.1.1; 160dpi; 540x960; Google/google; google Pixel 2; x86; qcom; tr_TR; 276028050)', - ]; - - $cookie = [ - 'mid' => 'YB2r4AABAAERcl5ESNxLjr_tt4Q5', - 'csrftoken' => 'YBck6oCPqG3e2YtLRxeiebBfVQawQm04', - ]; - - /* - $client = new \GuzzleHttp\Client([ - 'verify' => false, - 'headers' => $header - ]); - - $result = $client->post($url, - [ - 'form_params' => $post_data - ] - ); - */ - - $result = $this->request($url, 'POST', $post_data, $header); - print_r($result); - - } - public function login($username = null, $password = null){ - $username = $username??$this->username; - $password = $password??$this->password; + $username = $username ?? $this->username; + $password = $password ?? $this->password; $this->username = $username; $cookie = $this->cache('sessionid'); @@ -107,20 +58,62 @@ public function login($username = null, $password = null){ private function login_check($json = null){ if($json != null){ $json_body = json_decode($json['body']); - if($json_body->status == 'ok'){ - $cookie = $this->cache('sessionid'); - if($cookie == false){ - foreach($json['headers']['ig-set-authorization'] as $cookie){ - $this->cache('Bearer', $cookie); - preg_match('|Bearer IGT:(.*):(.*)|isu', $cookie,$session_json); - $session_json = json_decode(base64_decode($session_json[2])); - $this->cache('sessionid', $session_json->sessionid); + if(!isset($json_body->two_factor_required)){ + if($json_body->status == 'ok'){ + $cookie = $this->cache('sessionid'); + if($cookie == false){ + foreach($json['headers']['ig-set-authorization'] as $cookie){ + $this->cache('Bearer', $cookie); + preg_match('|Bearer IGT:(.*):(.*)|isu', $cookie, $session_json); + $session_json = json_decode(base64_decode($session_json[2])); + $this->cache('sessionid', $session_json->sessionid); + } } + return true; } - return true; } + else{ + return (object) [ + 'two_factor_identifier' => $json_body->two_factor_info->two_factor_identifier + ]; + } + } + return false; + } + + public function two_factor_login($code = null, $two_factor_identifier = null){ + + if($code != null and $two_factor_identifier != null){ + + $username = $this->username; + + $url = 'https://i.instagram.com/api/v1/accounts/two_factor_login/'; + $post_data = [ + 'verification_code' => $code, + 'phone_id' => $this->get_phone_id(), + 'two_factor_identifier' => $two_factor_identifier, + 'trust_this_device' => 1, + '_csrftoken' => $this->get_csrftoken(), + 'username' => $username, + 'adid' => $this->get_adid(), + 'guid' => $this->get_guid(), + 'device_id' => $this->get_device_id(), + 'verification_method' => 6, + ]; + $post_data = ['signed_body' => 'SIGNATURE.'.json_encode($post_data)]; + + $cookie = [ + 'mid' => 'YB2r4AABAAERcl5ESNxLjr_tt4Q5', + 'csrftoken' => $this->get_csrftoken(), + ]; + + $result = $this->request($url, 'POST', $post_data, null, $cookie); + return $this->login_check($result); + } + return false; + } public function login_control($username = null){ @@ -226,7 +219,7 @@ public function get_launcher_sync(){ public function logout($username = null){ - $username = $username??$this->username; + $username = $username ?? $this->username; $url = 'https://i.instagram.com/api/v1/accounts/logout/'; $post_data = [