Skip to content

Commit

Permalink
1.0.19
Browse files Browse the repository at this point in the history
- İki adımlı giriş işlemi eklendi.
  • Loading branch information
Hasokeyk committed Aug 11, 2021
1 parent de9fe07 commit c0173e7
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 63 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
<?php

use instagram\instagram;

require "/vendor/autoload.php";

$username = 'username';
$password = 'password';

$instagram = new instagram($username, $password);

if(isset($_REQUEST['two_factor_login_code'], $_REQUEST['two_factor_identifier']) and !empty($_REQUEST['two_factor_login_code']) and !empty($_REQUEST['two_factor_identifier'])){
$code = trim($_REQUEST['two_factor_login_code']);
$token = trim($_REQUEST['two_factor_identifier']);
$two_factor_login = $instagram->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
<form action="" method="post">
<input type="hidden" name="two_factor_identifier" value="$login->two_factor_identifier">
<input type="text" name="two_factor_login_code">
<input type="submit" value="Login">
</form>
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
Expand Down Expand Up @@ -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) |
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
34 changes: 34 additions & 0 deletions examples/user/instagram-user-two-factor-login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use instagram\instagram;

require "../../vendor/autoload.php";

$username = 'username';
$password = 'password';

$instagram = new instagram($username, $password);

if(isset($_REQUEST['two_factor_login_code'], $_REQUEST['two_factor_identifier']) and !empty($_REQUEST['two_factor_login_code']) and !empty($_REQUEST['two_factor_identifier'])){
$code = trim($_REQUEST['two_factor_login_code']);
$token = trim($_REQUEST['two_factor_identifier']);
$two_factor_login = $instagram->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
<form action="" method="post">
<input type="hidden" name="two_factor_identifier" value="$login->two_factor_identifier">
<input type="text" name="two_factor_login_code">
<input type="submit" value="Login">
</form>
END;
}
else if($instagram->login->login_control()){
echo 'Login Success';
}
else{
echo 'Login Fail';
}
}
115 changes: 54 additions & 61 deletions src/instagram_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit c0173e7

Please sign in to comment.