· 6 years ago · Oct 11, 2019, 09:05 PM
1<?php
2
3require __DIR__.'/vendor/autoload.php';
4$ig = new \InstagramAPI\Instagram();
5
6output_clean("
7 _ _ _
8| | | | | |
9| |_| |_ _ _ __ ___ _ __| | ___ ___ _ __
10| _ | | | | '_ \ / _ \ '__| |/ _ \ / _ \| '_ \
11| | | | |_| | |_) | __/ | | | (_) | (_) | |_) |
12\_| |_/\__, | .__/ \___|_| |_|\___/ \___/| .__/
13 __/ | | | |
14 |___/|_| |_|
15");
16
17output_clean("");
18output_clean("Hyperloop Terminal");
19output_clean("v.4.3 personalized");
20output_clean("");
21output_clean("© Developed by Nextpost Developers Team (https://nextpost.tech)");
22output_clean("");
23
24run($ig);
25
26/**
27 * Let's start the show
28 */
29function run($ig) {
30 try {
31
32 output('Please provide login data of your Instagram Account.');
33
34 $login = getVarFromUser("Login");
35 if (empty($login)) {
36 do {
37 $login = getVarFromUser("Login");
38 } while (empty($login));
39 }
40
41 $password = getVarFromUser("Password");
42 if (empty($password)) {
43 do {
44 $password = getVarFromUser("Password");
45 } while (empty($password));
46 }
47
48 $first_loop = true;
49 do {
50 if ($first_loop) {
51 output("(Optional) Set proxy, if needed. It's better to use a proxy from the same country where you running this script.");
52 output("Proxy should match following pattern:");
53 output("http://ip:port or http://username:password@ip:port");
54 output("Don't use in pattern https://.");
55 output("Type 3 to skip and don't use proxy.");
56 $first_loop = false;
57 } else {
58 output("Proxy - [NOT VALID]");
59 output("Please check the proxy syntax and try again.");
60 }
61
62 $proxy = getVarFromUser("Proxy");
63
64 if (empty($proxy)) {
65 do {
66 $proxy = getVarFromUser("Proxy");
67 } while (empty($proxy));
68 }
69
70 if ($proxy == '3') {
71 // Skip proxy setup
72 break;
73 }
74 } while (!isValidProxy($proxy));
75
76 if ($proxy == "3") {
77 // Skip proxy setup
78 } else {
79 output("Proxy - [OK]");
80 $ig->setProxy($proxy);
81 }
82
83 output('Please choose the masslooking estimated speed.');
84 output('Type integer value without spaces from 1 to 500 000 stories/day or 0 for maximum possible speed.');
85 output('When you are using the maximum speed you may exceed the masslooking limits per day if this account actively used by a user in the Instagram app at the same time.');
86 output('If you are using another type of automation, we recommend to you reducing masslooking speed to find your golden ratio. In that case we recommend 400 000 stories/day.');
87 $speed = (int)getVarFromUser("Speed");
88
89 if ($speed > 500000) {
90 do {
91 output("Speed value is incorrect. Type integer value from 1 to 500 000 stories/day.");
92 output('Type 0 for maximum speed.');
93 $speed = (int)getVarFromUser("Delay");
94 } while ($speed > 500000);
95 }
96
97 if ($speed == 0) {
98 output("Maximum speed enabled.");
99 $delay = 34;
100 } else {
101 output("Speed set to " . $speed . " stories/day.");
102 $delay = round(60*60*24*200/$speed);
103 }
104
105 $is_connected = false;
106 $is_connected_count = 0;
107 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
108
109 do {
110 if ($is_connected_count == 10) {
111 if ($e->getResponse()) {
112 output($e->getMessage());
113 }
114 throw new Exception($fail_message);
115 }
116
117 try {
118 if ($is_connected_count == 0) {
119 output("Emulation of an Instagram app initiated...");
120 }
121 $login_resp = $ig->login($login, $password);
122
123 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
124 // Default verification method is phone
125 $twofa_method = '1';
126
127 // Detect is Authentification app verification is available
128 $is_totp = json_decode(json_encode($login_resp), true);
129 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
130 output("Two-factor authentication required, please enter the code from you Authentication app");
131 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
132 $twofa_method = '3';
133 } else {
134 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
135 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
136 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
137 }
138
139 $twofa_code = getVarFromUser("Two-factor code");
140
141 if (empty($twofa_code)) {
142 do {
143 $twofa_code = getVarFromUser("Two-factor code");
144 } while (empty($twofa_code));
145 }
146
147 $is_connected = false;
148 $is_connected_count = 0;
149 do {
150 if ($is_connected_count == 10) {
151 if ($e->getResponse()) {
152 output($e->getMessage());
153 }
154 throw new Exception($fail_message);
155 }
156
157 if ($is_connected_count == 0) {
158 output("Two-factor authentication in progress...");
159 }
160
161 try {
162 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
163 $is_connected = true;
164 } catch (\InstagramAPI\Exception\NetworkException $e) {
165 sleep(7);
166 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
167 sleep(7);
168 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
169 $is_code_correct = false;
170 $is_connected= true;
171 do {
172 output("Code is incorrect. Please check the syntax and try again.");
173 $twofa_code = getVarFromUser("Two-factor code");
174
175 if (empty($twofa_code)) {
176 do {
177 $twofa_code = getVarFromUser("Security code");
178 } while (empty($twofa_code));
179 }
180
181 $is_connected = false;
182 $is_connected_count = 0;
183 do {
184 try {
185 if ($is_connected_count == 10) {
186 if ($e->getResponse()) {
187 output($e->getMessage());
188 }
189 throw new Exception($fail_message);
190 }
191
192 if ($is_connected_count == 0) {
193 output("Verification in progress...");
194 }
195 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
196 $is_code_correct = true;
197 $is_connected = true;
198 } catch (\InstagramAPI\Exception\NetworkException $e) {
199 sleep(7);
200 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
201 sleep(7);
202 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
203 $is_code_correct = false;
204 $is_connected = true;
205 } catch (\Exception $e) {
206 throw $e;
207 }
208 $is_connected_count += 1;
209 } while (!$is_connected);
210 } while (!$is_code_correct);
211 } catch (\Exception $e) {
212 throw $e;
213 }
214
215 $is_connected_count += 1;
216 } while (!$is_connected);
217 }
218
219 $is_connected = true;
220 } catch (\InstagramAPI\Exception\NetworkException $e) {
221 sleep(7);
222 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
223 sleep(7);
224 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
225 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
226 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
227
228 if (!($ig instanceof InstagramAPI\Instagram)) {
229 throw new Exception("Oops! Something went wrong. Please try again later! (invalid_instagram_client)");
230 }
231
232 if (!($e instanceof InstagramAPI\Exception\ChallengeRequiredException)) {
233 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception)");
234 }
235
236 if (!$e->hasResponse() || !$e->getResponse()->isChallenge()) {
237 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception_response)");
238 }
239
240 $challenge = $e->getResponse()->getChallenge();
241
242 if (is_array($challenge)) {
243 $api_path = $challenge["api_path"];
244 } else {
245 $api_path = $challenge->getApiPath();
246 }
247
248 output("Instagram want to send you a security code to verify your identity.");
249 output("How do you want receive this code?");
250 output("1 - [Email]");
251 output("2 - [SMS]");
252 output("3 - [Exit]");
253
254 $choice = getVarFromUser("Choice");
255
256 if (empty($choice)) {
257 do {
258 $choice = getVarFromUser("Choice");
259 } while (empty($choice));
260 }
261
262 if ($choice == '1' || $choice == '2' || $choice == '3') {
263 // All fine
264 } else {
265 $is_choice_ok = false;
266 do {
267 output("Choice is incorrect. Type 1, 2 or 3.");
268 $choice = getVarFromUser("Choice");
269
270 if (empty($choice)) {
271 do {
272 $choice = getVarFromUser("Choice");
273 } while (empty($choice));
274 }
275
276 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
277 $is_choice_ok = true;
278 }
279 } while (!$is_choice_ok);
280 }
281
282 $challange_choice = 0;
283 if ($choice == '3') {
284 run($ig);
285 } elseif ($choice == '1') {
286 // Email
287 $challange_choice = 1;
288 } else {
289 // SMS
290 $challange_choice = 0;
291 }
292
293 $is_connected = false;
294 $is_connected_count = 0;
295 do {
296 if ($is_connected_count == 10) {
297 if ($e->getResponse()) {
298 output($e->getMessage());
299 }
300 throw new Exception($fail_message);
301 }
302
303 try {
304 $challenge_resp = $ig->sendChallangeCode($api_path, $challange_choice);
305
306 // Failed to send challenge code via email. Try with SMS.
307 if ($challenge_resp->status != "ok") {
308 $challange_choice = 0;
309 sleep(7);
310 $challenge_resp = $ig->sendChallangeCode($api_path, $challange_choice);
311 }
312
313 $is_connected = true;
314 } catch (\InstagramAPI\Exception\NetworkException $e) {
315 sleep(7);
316 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
317 sleep(7);
318 } catch (\Exception $e) {
319 throw $e;
320 }
321
322 $is_connected_count += 1;
323 } while (!$is_connected);
324
325 if ($challenge_resp->status != "ok") {
326 if (isset($challenge_resp->message)) {
327 if ($challenge_resp->message == "This field is required.") {
328 output("We received the response 'This field is required.'. This can happen in 2 reasons:");
329 output("1. Instagram already sent to you verification code to your email or mobile phone number. Please enter this code.");
330 output("2. Instagram forced you to phone verification challenge. Try login to Instagram app or website and take a look at what happened.");
331 }
332 } else {
333 output("Instagram Response: " . json_encode($challenge_resp));
334 output("Couldn't send a verification code for the login challenge. Please try again later.");
335 output("- Is this account has attached mobile phone number in settings?");
336 output("- If no, this can be a reason of this problem. You should add mobile phone number in account settings.");
337 throw new Exception("- Sometimes Instagram can force you to phone verification challenge process.");
338 }
339 }
340
341 if (isset($challenge_resp->step_data->contact_point)){
342 $contact_point = $challenge_resp->step_data->contact_point;
343 if ($choice == 2) {
344 output("Enter the code sent to your number ending in " . $contact_point . ".");
345 } else {
346 output("Enter the 6-digit code sent to the email address " . $contact_point . ".");
347 }
348 }
349
350 $security_code = getVarFromUser("Security code");
351
352 if (empty($security_code)) {
353 do {
354 $security_code = getVarFromUser("Security code");
355 } while (empty($security_code));
356 }
357
358 if ($security_code == "3") {
359 throw new Exception("Reset in progress...");
360 }
361
362 // Verification challenge
363 $ig = challange($ig, $login, $password, $api_path, $security_code, $proxy);
364
365 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
366 throw new Exception("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
367 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
368 throw new Exception("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
369 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
370 throw new Exception("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
371 } catch (\InstagramAPI\Exception\IncorrectPasswordException $e) {
372 throw new Exception("The password you entered is incorrect. Please try again.");
373 } catch (\InstagramAPI\Exception\InvalidUserException $e) {
374 throw new Exception("The username you entered doesn't appear to belong to an account. Please check your username and try again.");
375 } catch (\Exception $e) {
376 throw $e;
377 }
378
379 $is_connected_count += 1;
380 } while (!$is_connected);
381
382 output("Logged as @" . $login . " successfully.");
383
384 $data = define_targets($ig);
385
386 // Disabled, because this feature not supported at the moment
387 // Because of new Instagram limits
388 $is_parsers_enabled = false;
389
390 if (!$is_parsers_enabled) {
391 masslooking_v2($data, $ig, $delay);
392 } else {
393 output('Do you want to add parsers? (additional Instagram accounts for speed up masslooking speed)');
394 output("1 - [Yes]");
395 output("2 - [No]");
396 output("3 - [Exit]");
397
398 $confirm_p = getVarFromUser("Choice");
399
400 if (empty($confirm_p)) {
401 do {
402 $confirm_p = getVarFromUser("Choice");
403 } while (empty($confirm_p));
404 }
405
406 if ($confirm_p == '1' || $confirm_p == '2' || $confirm_p == '3') {
407 // All fine
408 } else {
409 $is_choice_ok = false;
410 do {
411 output("Choice is incorrect. Type 1, 2 or 3.");
412 $confirm_p = getVarFromUser("Choice");
413
414 if (empty($confirm_p)) {
415 do {
416 $confirm_p = getVarFromUser("Choice");
417 } while (empty($confirm_p));
418 }
419
420 if ($confirm_p == '1' || $confirm_p == '2' || $confirm_p == '3') {
421 $is_choice_ok = true;
422 }
423 } while (!$is_choice_ok);
424 }
425
426 if ($confirm_p == '3') {
427 throw new Exception("Reset in progress...");
428 } elseif ($confirm_p == '2') {
429 masslooking_v2($data, $ig, $delay);
430 } else {
431 // Yes, I want to add parsers.
432 }
433
434 output('How many parsers do you want to add? (integer value from 1 to 5)');
435 output("Type 11 - to don't use parsers and start masslooking.");
436 output("Type 12 - to exit.");
437 $parsers_count = (int)getVarFromUser("Parsers count");
438
439 if ($parsers_count > 12) {
440 do {
441 output("Parsers count is incorrect. Type integer value from 1 to 12.");
442 $parsers_count = (int)getVarFromUser("Parsers count");
443 } while ($parsers_count > 12);
444 }
445
446 if ($parsers_count == 11) {
447 masslooking_v2($data, $ig, $delay);
448 } elseif ($parsers_count == 12) {
449 throw new Exception("Reset in progress...");
450 } else {
451 output("You want to add " . $parsers_count . " parser(s).");
452 output("Let's get started.");
453 }
454
455 for ($i = 1; $i < count($parsers_count); $i++) {
456 $ig_p[] = add_parser($i);
457 }
458
459 output("All " . $parsers_count . " parser(s) successfully connected.");
460
461 // $user_resp = $ig->people->getInfoById($data[0]["pk"]);
462 // output(json_encode($user_resp));
463
464 // $user_resp = $ig_p[1]->people->getInfoById($data[1]["pk"]);
465 // output(json_encode($user_resp));
466
467 // $user_resp = $ig_p[2]->people->getInfoById($data[2]["pk"]);
468 // output(json_encode($user_resp));
469
470 }
471
472 } catch (\Exception $e){
473 output($e->getMessage());
474 output("Please run script command again.");
475 exit;
476 }
477}
478
479/**
480 * Add parser
481 */
482function add_parser($pn) {
483 try {
484 $igp = new \InstagramAPI\Instagram();
485
486 output("Please provide login data of your parser #" . $pn . " (additional Instagram account for speed up masslooking speed)");
487
488 $login = getVarFromUser("Login");
489 if (empty($login)) {
490 do {
491 $login = getVarFromUser("Login");
492 } while (empty($login));
493 }
494
495 $password = getVarFromUser("Password");
496 if (empty($password)) {
497 do {
498 $password = getVarFromUser("Password");
499 } while (empty($password));
500 }
501
502 $first_loop = true;
503 do {
504 if ($first_loop) {
505 output("(Optional) Set proxy, if needed. It's better to use a proxy from the country from you running this script.");
506 output("Proxy should match following pattern:");
507 output("http://ip:port or http://username:password@ip:port");
508 output("Don't use in pattern https://.");
509 output("Type 3 to skip and don't use proxy.");
510 $first_loop = false;
511 } else {
512 output("Proxy - [NOT VALID]");
513 output("Please check the proxy syntax and try again.");
514 }
515
516 $proxy = getVarFromUser("Proxy");
517
518 if (empty($proxy)) {
519 do {
520 $proxy = getVarFromUser("Proxy");
521 } while (empty($proxy));
522 }
523
524 if ($proxy == '3') {
525 // Skip proxy setup
526 break;
527 }
528 } while (!isValidProxy($proxy));
529
530 if ($proxy == "3") {
531 // Skip proxy setup
532 } else {
533 output("Proxy - [OK]");
534 $igp->setProxy($proxy);
535 }
536
537 $is_connected = false;
538 $is_connected_count = 0;
539 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
540
541 do {
542 if ($is_connected_count == 10) {
543 if ($e->getResponse()) {
544 output($e->getMessage());
545 }
546 throw new Exception($fail_message);
547 }
548
549 try {
550 if ($is_connected_count == 0) {
551 output("Emulation of an Instagram app for parser #" . $pn . " initiated...");
552 }
553 $login_resp = $igp->login($login, $password);
554
555 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
556 // Default verification method is phone
557 $twofa_method = '1';
558
559 // Detect is Authentification app verification is available
560 $is_totp = json_decode(json_encode($login_resp), true);
561 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
562 output("Two-factor authentication required, please enter the code from you Authentication app");
563 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
564 $twofa_method = '3';
565 } else {
566 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
567 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
568 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
569 }
570
571 $twofa_code = getVarFromUser("Two-factor code");
572
573 if (empty($twofa_code)) {
574 do {
575 $twofa_code = getVarFromUser("Two-factor code");
576 } while (empty($twofa_code));
577 }
578
579 $is_connected = false;
580 $is_connected_count = 0;
581 do {
582 if ($is_connected_count == 10) {
583 if ($e->getResponse()) {
584 output($e->getMessage());
585 }
586 throw new Exception($fail_message);
587 }
588
589 if ($is_connected_count == 0) {
590 output("Two-factor authentication in progress...");
591 }
592
593 try {
594 $twofa_resp = $igp->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
595 $is_connected = true;
596 } catch (\InstagramAPI\Exception\NetworkException $e) {
597 sleep(7);
598 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
599 sleep(7);
600 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
601 $is_code_correct = false;
602 $is_connected= true;
603 do {
604 output("Code is incorrect. Please check the syntax and try again.");
605 $twofa_code = getVarFromUser("Two-factor code");
606
607 if (empty($twofa_code)) {
608 do {
609 $twofa_code = getVarFromUser("Security code");
610 } while (empty($twofa_code));
611 }
612
613 $is_connected = false;
614 $is_connected_count = 0;
615 do {
616 try {
617 if ($is_connected_count == 10) {
618 if ($e->getResponse()) {
619 output($e->getMessage());
620 }
621 throw new \Exception($fail_message);
622 }
623
624 if ($is_connected_count == 0) {
625 output("Verification in progress...");
626 }
627 $twofa_resp = $igp->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
628 $is_code_correct = true;
629 $is_connected = true;
630 } catch (\InstagramAPI\Exception\NetworkException $e) {
631 sleep(7);
632 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
633 sleep(7);
634 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
635 $is_code_correct = false;
636 $is_connected = true;
637 } catch (\Exception $e) {
638 throw $e;
639 }
640 $is_connected_count += 1;
641 } while (!$is_connected);
642 } while (!$is_code_correct);
643 } catch (\Exception $e) {
644 throw $e;
645 }
646
647 $is_connected_count += 1;
648 } while (!$is_connected);
649 }
650
651 $is_connected = true;
652 } catch (\InstagramAPI\Exception\NetworkException $e) {
653 sleep(7);
654 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
655 sleep(7);
656 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
657 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
658 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
659
660 if (!($igp instanceof InstagramAPI\Instagram)) {
661 throw new Exception("Oops! Something went wrong. Please try again later! (invalid_instagram_client)");
662 }
663
664 if (!($e instanceof InstagramAPI\Exception\ChallengeRequiredException)) {
665 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception)");
666 }
667
668 if (!$e->hasResponse() || !$e->getResponse()->isChallenge()) {
669 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception_response)");
670 }
671
672 $challenge = $e->getResponse()->getChallenge();
673
674 if (is_array($challenge)) {
675 $api_path = $challenge["api_path"];
676 } else {
677 $api_path = $challenge->getApiPath();
678 }
679
680 output("Instagram will send you a security code to verify your identity.");
681 output("How do you want receive this code?");
682 output("1 - [Email]");
683 output("2 - [SMS]");
684 output("3 - [Exit]");
685
686 $choice = getVarFromUser("Choice");
687
688 if (empty($choice)) {
689 do {
690 $choice = getVarFromUser("Choice");
691 } while (empty($choice));
692 }
693
694 if ($choice == '1' || $choice == '2' || $choice == '3') {
695 // All fine
696 } else {
697 $is_choice_ok = false;
698 do {
699 output("Choice is incorrect. Type 1, 2 or 3.");
700 $choice = getVarFromUser("Choice");
701
702 if (empty($choice)) {
703 do {
704 $choice = getVarFromUser("Choice");
705 } while (empty($choice));
706 }
707
708 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
709 $is_choice_ok = true;
710 }
711 } while (!$is_choice_ok);
712 }
713
714 $challange_choice = 0;
715 if ($choice == '3') {
716 throw new Exception("Reset in progress...");
717 } elseif ($choice == '1') {
718 // Email
719 $challange_choice = 1;
720 } else {
721 // SMS
722 $challange_choice = 0;
723 }
724
725 $is_connected = false;
726 $is_connected_count = 0;
727 do {
728 if ($is_connected_count == 10) {
729 if ($e->getResponse()) {
730 output($e->getMessage());
731 }
732 throw new Exception($fail_message);
733 }
734
735 try {
736 $challenge_resp = $igp->sendChallangeCode($api_path, $challange_choice);
737
738 // Failed to send challenge code via email. Try with SMS.
739 if ($challenge_resp->status != "ok") {
740 $challange_choice = 0;
741 $challenge_resp = $igp->sendChallangeCode($api_path, $challange_choice);
742 }
743
744 $is_connected = true;
745 } catch (\InstagramAPI\Exception\NetworkException $e) {
746 sleep(7);
747 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
748 sleep(7);
749 } catch (\Exception $e) {
750 throw $e;
751 }
752
753 $is_connected_count += 1;
754 } while (!$is_connected);
755
756 if ($challenge_resp->message == "This field is required.") {
757 output("Instagram already sent to you verification code to your email or mobile phone number. Please enter this code.");
758 } elseif ($challenge_resp->status != "ok") {
759 throw new Exception("Couldn't send a verification code for the login challenge. Please try again later.");
760 }
761
762 if (isset($challenge_resp->step_data->contact_point)){
763 $contact_point = $challenge_resp->step_data->contact_point;
764 if ($choice == 2) {
765 output("Enter the code sent to your number ending in " . $contact_point . ".");
766 } else {
767 output("Enter the 6-digit code sent to the email address " . $contact_point . ".");
768 }
769 }
770
771 output("Type 3 - to exit.");
772
773 $security_code = getVarFromUser("Security code");
774
775 if (empty($security_code)) {
776 do {
777 $security_code = getVarFromUser("Security code");
778 } while (empty($security_code));
779 }
780
781 if ($security_code == "3") {
782 throw new Exception("Reset in progress...");
783 }
784
785 // Verification challenge
786 $igp = challange($igp, $login, $password, $api_path, $security_code, $proxy);
787
788 if ($igp == "3") {
789 throw new Exception("Reset in progress...");
790 }
791
792 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
793 throw new Exception("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
794 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
795 throw new Exception("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
796 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
797 throw new Exception("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
798 } catch (\InstagramAPI\Exception\IncorrectPasswordException $e) {
799 throw new Exception("The password you entered is incorrect. Please try again.");
800 } catch (\InstagramAPI\Exception\InvalidUserException $e) {
801 throw new Exception("The username you entered doesn't appear to belong to an account. Please check your username and try again.");
802 } catch (\Exception $e) {
803 throw $e;
804 }
805
806 $is_connected_count += 1;
807 } while (!$is_connected);
808
809 output("Logged as @" . $login . " successfully. Parser #" . $pn . " connected.");
810
811 } catch (\Exception $e){
812 output($e->getMessage());
813 $igp = add_parser($pn);
814 }
815
816 return $igp;
817}
818
819/**
820 * Define targets for masslooking
821 */
822function define_targets($ig) {
823
824 do {
825 output("Please define the targets.");
826 output("Write all Instagram profile usernames via comma without '@' symbol.");
827 output("Example: apple, instagram, zendaya");
828 $targets_input = getVarFromUser("Usernames");
829
830 if (empty($targets_input)) {
831 do {
832 $targets_input = getVarFromUser("Usernames");
833 } while (empty($targets_input));
834 }
835
836 $targets_input = str_replace(' ','',$targets_input);
837 $targets = [];
838 $targets = explode(',',trim($targets_input));
839 $targets = array_unique($targets);
840
841 $pks = [];
842 $filtered_targets = [];
843 foreach ($targets as $target) {
844
845 $is_connected = false;
846 $is_connected_count = 0;
847 do {
848 if ($is_connected_count == 10) {
849 if ($e->getResponse()) {
850 output($e->getMessage());
851 }
852 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
853 output($fail_message);
854 run($ig);
855 }
856
857 try {
858 $user_resp = $ig->people->getUserIdForName($target);
859 output("@" . $target . " - [OK]");
860 $filtered_targets[] = $target;
861 $pks[] = $user_resp;
862 $is_connected = true;
863 if (($target != $targets[count($targets) - 1]) && (count($targets) > 0)) {
864 sleep(1);
865 }
866 } catch (\InstagramAPI\Exception\NetworkException $e) {
867 sleep(7);
868 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
869 sleep(7);
870 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
871 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
872 run($ig);
873 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
874 output("Please go to Instagram website or mobile app and pass checkpoint!");
875 run($ig);
876 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
877 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
878 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
879 run($ig);
880 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
881 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
882 run($ig);
883 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
884 output("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
885 run($ig);
886 } catch (\InstagramAPI\Exception\ThrottledException $e) {
887 output("Throttled by Instagram because of too many API requests.");
888 output("Please login again after 1 hour. You reached Instagram limits.");
889 run($ig);
890 } catch (InstagramAPI\Exception\NotFoundException $e) {
891 $is_connected = true;
892 $is_username_correct = false;
893 do {
894 output("Instagram profile username @" . $target . " is incorrect or maybe user just blocked you (Login to Instagram website or mobile app and check that).");
895 output("Type 3 for skip this target.");
896 $target_new = getVarFromUser("Please provide valid username");
897
898 if (empty($target_new)) {
899 do {
900 $target_new = getVarFromUser("Please provide valid username");
901 } while (empty($target_new));
902 }
903
904 if ($target_new == "3") {
905 break;
906 } else {
907 $is_connected = false;
908 $is_connected_count = 0;
909 do {
910 if ($is_connected_count == 10) {
911 if ($e->getResponse()) {
912 output($e->getMessage());
913 }
914 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
915 output($fail_message);
916 run($ig);
917 }
918
919 try {
920 $user_resp = $ig->people->getUserIdForName($target_new);
921 output("@" . $target_new . " - [OK]");
922 $filtered_targets[] = $target_new;
923 $pks[] = $user_resp;
924 $is_username_correct = true;
925 $is_connected = true;
926 } catch (\InstagramAPI\Exception\NetworkException $e) {
927 sleep(7);
928 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
929 sleep(7);
930 } catch (InstagramAPI\Exception\NotFoundException $e) {
931 $is_username_correct = false;
932 $is_connected = true;
933 } catch (\Exception $e) {
934 output($e->getMessage());
935 run($ig);
936 }
937 $is_connected_count += 1;
938 } while (!$is_connected);
939 }
940 } while (!$is_username_correct);
941 } catch (Exception $e){
942 output($e->getMessage());
943 run($ig);
944 }
945
946 $is_connected_count += 1;
947 } while (!$is_connected);
948 }
949 } while (empty($filtered_targets));
950
951 $targets = array_unique($filtered_targets);
952 $pks = array_unique($pks);
953
954 $data = [];
955 for ($i = 0; $i < count($targets); $i++) {
956 $data[$i] = [
957 'username' => $targets[$i],
958 'pk' => $pks[$i],
959 ];
960 }
961
962 output("Selected " . count($targets) . " targets: @" . implode(", @", $targets) . ".");
963 output("Please confirm that the selected targets are correct.");
964 output("1 - [Yes]");
965 output("2 - [No]");
966 output("3 - [Exit]");
967
968 $confirm = getVarFromUser("Choice");
969
970 if (empty($confirm)) {
971 do {
972 $confirm = getVarFromUser("Choice");
973 } while (empty($confirm));
974 }
975
976 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
977 // All fine
978 } else {
979 $is_choice_ok = false;
980 do {
981 output("Choice is incorrect. Type 1, 2 or 3.");
982 $confirm = getVarFromUser("Choice");
983
984 if (empty($confirm)) {
985 do {
986 $confirm = getVarFromUser("Choice");
987 } while (empty($confirm));
988 }
989
990 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
991 $is_choice_ok = true;
992 }
993 } while (!$is_choice_ok);
994 }
995
996 if ($confirm == '3') {
997 run($ig);
998 } elseif ($confirm == '2') {
999 $data = define_targets($ig);
1000 } else {
1001 // All fine. Going to masslooking.
1002 }
1003
1004 return $data;
1005}
1006
1007/**
1008 * Get varable from user
1009 */
1010function getVarFromUser($text) {
1011 echo $text . ": ";
1012 $var = trim(fgets(STDIN));
1013 return $var;
1014}
1015
1016/**
1017 * Output message with data to console
1018 */
1019function output($message) {
1020 echo "[", date("H:i:s"), "] ", $message, PHP_EOL;
1021}
1022
1023/**
1024 * Output clean message to console
1025 */
1026function output_clean($message) {
1027 echo $message, PHP_EOL;
1028}
1029
1030/**
1031 * Validates proxy address
1032 */
1033function isValidProxy($proxy) {
1034 output("Connecting to Instagram...");
1035
1036 try {
1037 $client = new \GuzzleHttp\Client();
1038 $res = $client->request('GET', 'http://www.instagram.com',
1039 [
1040 "timeout" => 60,
1041 "proxy" => $proxy
1042 ]);
1043 $code = $res->getStatusCode();
1044 $is_connected = true;
1045 } catch (\Exception $e) {
1046 output($e->getMessage());
1047 return false;
1048 }
1049
1050 return $code == 200;
1051}
1052
1053/**
1054 * Validates proxy address
1055 */
1056function finishLogin($ig, $login, $password, $proxy) {
1057 $is_connected = false;
1058 $is_connected_count = 0;
1059
1060 try {
1061 do {
1062 if ($is_connected_count == 10) {
1063 if ($e->getResponse()) {
1064 output($e->getMessage());
1065 }
1066 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
1067 output($fail_message);
1068 run($ig);
1069 }
1070
1071 if ($proxy == "3") {
1072 // Skip proxy setup
1073 } else {
1074 $ig->setProxy($proxy);
1075 }
1076
1077 try {
1078 $login_resp = $ig->login($login, $password);
1079
1080 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
1081 // Default verification method is phone
1082 $twofa_method = '1';
1083
1084 // Detect is Authentification app verification is available
1085 $is_totp = json_decode(json_encode($login_resp), true);
1086 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
1087 output("Two-factor authentication required, please enter the code from you Authentication app");
1088 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1089 $twofa_method = '3';
1090 } else {
1091 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
1092 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
1093 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1094 }
1095
1096 $twofa_code = getVarFromUser("Two-factor code");
1097
1098 if (empty($twofa_code)) {
1099 do {
1100 $twofa_code = getVarFromUser("Two-factor code");
1101 } while (empty($twofa_code));
1102 }
1103
1104 $is_connected = false;
1105 $is_connected_count = 0;
1106 do {
1107 if ($is_connected_count == 10) {
1108 if ($e->getResponse()) {
1109 output($e->getMessage());
1110 }
1111 output($fail_message);
1112 run($ig);
1113 }
1114
1115 if ($is_connected_count == 0) {
1116 output("Two-factor authentication in progress...");
1117 }
1118
1119 try {
1120 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1121 $is_connected = true;
1122 } catch (\InstagramAPI\Exception\NetworkException $e) {
1123 sleep(7);
1124 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1125 sleep(7);
1126 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1127 $is_code_correct = false;
1128 $is_connected= true;
1129 do {
1130 output("Code is incorrect. Please check the syntax and try again.");
1131 $twofa_code = getVarFromUser("Two-factor code");
1132
1133 if (empty($twofa_code)) {
1134 do {
1135 $twofa_code = getVarFromUser("Security code");
1136 } while (empty($twofa_code));
1137 }
1138
1139 $is_connected = false;
1140 $is_connected_count = 0;
1141 do {
1142 try {
1143 if ($is_connected_count == 10) {
1144 if ($e->getResponse()) {
1145 output($e->getMessage());
1146 }
1147 output($fail_message);
1148 run($ig);
1149 }
1150
1151 if ($is_connected_count == 0) {
1152 output("Verification in progress...");
1153 }
1154 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1155 $is_code_correct = true;
1156 $is_connected = true;
1157 } catch (\InstagramAPI\Exception\NetworkException $e) {
1158 sleep(7);
1159 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1160 sleep(7);
1161 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1162 $is_code_correct = false;
1163 $is_connected = true;
1164 } catch (\Exception $e) {
1165 throw new $e;
1166 }
1167 $is_connected_count += 1;
1168 } while (!$is_connected);
1169 } while (!$is_code_correct);
1170 } catch (\Exception $e) {
1171 throw $e;
1172 }
1173
1174 $is_connected_count += 1;
1175 } while (!$is_connected);
1176 }
1177
1178 $is_connected = true;
1179 } catch (\InstagramAPI\Exception\NetworkException $e) {
1180 sleep(7);
1181 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1182 sleep(7);
1183 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1184 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
1185 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1186 output("Instagram Response: " . json_encode($e->gerResponse()));
1187 output("Couldn't complete the verification challenge. Please try again later.");
1188 throw new Exception("Developer code: Challenge loop.");
1189 } catch (\Exception $e) {
1190 throw $e;
1191 }
1192
1193 $is_connected_count += 1;
1194 } while (!$is_connected);
1195 } catch (\Exception $e){
1196 output($e->getMessage());
1197 run($ig);
1198 }
1199
1200 return $ig;
1201}
1202
1203/**
1204 * Verification challenge
1205 */
1206function challange($ig, $login, $password, $api_path, $security_code, $proxy) {
1207 $is_connected = false;
1208 $is_connected_count = 0;
1209 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
1210
1211 do {
1212 if ($is_connected_count == 10) {
1213 if ($e->getResponse()) {
1214 output($e->getMessage());
1215 }
1216 throw new Exception($fail_message);
1217 }
1218
1219 if ($is_connected_count == 0) {
1220 output("Verification in progress...");
1221 }
1222
1223 try {
1224 $challenge_resp = $ig->finishChallengeLogin($login, $password, $api_path, $security_code);
1225 $is_connected = true;
1226 } catch (\InstagramAPI\Exception\NetworkException $e) {
1227 sleep(7);
1228 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1229 sleep(7);
1230 } catch (\InstagramAPI\Exception\InstagramException $e) {
1231
1232 if ($e->hasResponse()) {
1233 $msg = $e->getResponse()->getMessage();
1234 output($msg);
1235 } else {
1236 $msg = explode(":", $e->getMessage(), 2);
1237 $msg = end($msg);
1238 output($msg);
1239 }
1240
1241 output("Type 3 - to exit.");
1242
1243 $security_code = getVarFromUser("Security code");
1244
1245 if (empty($security_code)) {
1246 do {
1247 $security_code = getVarFromUser("Security code");
1248 } while (empty($security_code));
1249 }
1250
1251 if ($security_code == "3") {
1252 throw new Exception("Reset in progress...");
1253 }
1254
1255 } catch (\Exception $e) {
1256 $msg = $e->getMessage();
1257 if ($msg == 'Invalid Login Response at finishChallengeLogin().') {
1258 sleep(7);
1259 $ig = finishLogin($ig, $login, $password, $proxy);
1260 $is_connected = true;
1261 } else {
1262 throw $e;
1263 }
1264 }
1265
1266 $is_connected_count += 1;
1267 } while (!$is_connected);
1268
1269 return $ig;
1270}
1271
1272/**
1273 * Masslooking loop - Algorithm #2
1274 */
1275function masslooking_v2($data, $ig, $delay) {
1276
1277 $view_count = 0;
1278 $st_count = 0;
1279 $st_count_seen = 0;
1280 $begin = strtotime(date("Y-m-d H:i:s"));
1281 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1282 $begin_f = strtotime(date("Y-m-d H:i:s"));
1283 $speed = 0;
1284 $delitel = 0;
1285 $counter1 = 0;
1286 $counter2 = 0;
1287 $stories = [];
1288
1289 output("Masslooking loop started.");
1290
1291 $targets = [];
1292 $targets = $data;
1293
1294 for ($i = 0; $i < count($data); $i++) {
1295 $data[$i] += [
1296 'rank_token' => \InstagramAPI\Signatures::generateUUID(),
1297 'users_count' => 0,
1298 'max_id' => null,
1299 'begin_gf' => null
1300 ];
1301 }
1302
1303 do {
1304 foreach ($data as $key => $d) {
1305 try {
1306 if ($d['max_id'] == null) {
1307 $is_gf_first = 1;
1308 }
1309
1310 if (!empty($d['begin_gf'])) {
1311 $current_time = strtotime(date("Y-m-d H:i:s"));
1312 if (($current_time - $d['begin_gf']) < 7) {
1313 $sleep_time = 7 - ($current_time - $d['begin_gf']);
1314 sleep($sleep_time);
1315 }
1316 }
1317
1318 $followers = $ig->people->getFollowers($d['pk'], $d['rank_token'], null, $d['max_id']);
1319 $data[$key]['begin_gf'] = strtotime(date("Y-m-d H:i:s"));
1320
1321 if (empty($followers->getUsers())) {
1322 output("@" . $d['username'] . " don't have any follower.");
1323 unset($data[$key]);
1324 continue;
1325 }
1326
1327 // Get next $max_id value
1328 $data[$key]['max_id'] = $followers->getNextMaxId();
1329
1330 $followers_ids = [];
1331 foreach ($followers->getUsers() as $follower) {
1332 $followers_ids[] = $follower->getPk();
1333 }
1334
1335 $data[$key]['users_count'] = $d['users_count'] + count($followers_ids);
1336
1337 $number = count($followers_ids);
1338
1339 if ($is_gf_first) {
1340 output($number . " followers of @" . $d['username'] . " collected.");
1341 $is_gf_first = 0;
1342 } else {
1343 output("Next " . $number . " followers of @" . $d['username'] . " collected. Total: " . number_format($data[$key]['users_count'], 0, '.', ' ') . " followers of @" . $d['username'] . " parsed.");
1344 }
1345
1346 $index_new = 0;
1347 $index_old = 0;
1348 $last = false;
1349
1350 do {
1351 $index_new += 13;
1352
1353 if (!isset($followers_ids[$index_new])) {
1354 do {
1355 $index_new -= 1;
1356 } while (!isset($followers_ids[$index_new]));
1357 $last = true;
1358 }
1359
1360 if ($index_new < $index_old) {
1361 break;
1362 }
1363
1364 $ids = [];
1365 for ($i = $index_old; $i <= $index_new; $i++) {
1366 $ids[] = $followers_ids[$i];
1367 }
1368
1369 try {
1370 $stories_reels = $ig->story->getReelsMediaFeed($ids);
1371
1372 $counter1 += 1;
1373
1374 if (isset($stories_reels) && $stories_reels->isOk() && count($stories_reels->getReels()->getData()) > 0) {
1375 // Save user story reels's to array
1376 $reels = [];
1377 $reels = $stories_reels->getReels()->getData();
1378
1379 foreach ($reels as $r) {
1380 $items = [];
1381 $stories_loop = [];
1382 $items = $r->getItems();
1383
1384 foreach ($items as $item) {
1385 if (!$item->getId()) {
1386 // Item is not valid
1387 continue;
1388 }
1389 $stories_loop[] = $item;
1390 }
1391
1392 if (empty($stories)) {
1393 $stories = $stories_loop;
1394 } else {
1395 $stories = array_merge($stories, $stories_loop);
1396 }
1397
1398 $st_count = $st_count + count($stories_loop);
1399 $view_count = $view_count + count($stories_loop);
1400
1401 $now = strtotime(date("Y-m-d H:i:s"));
1402 if ($now - $begin > 299) {
1403 $begin = strtotime(date("Y-m-d H:i:s"));
1404 $delitel = $delitel + 1;
1405 $speed = (int)($view_count * 12 * 24 / $delitel);
1406 output_clean("");
1407 output_clean("Estimated speed is " . number_format($speed, 0, '.', ' ') . " stories/day.");
1408 output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1409 output_clean("");
1410 }
1411
1412 $now_f = strtotime(date("Y-m-d H:i:s"));
1413 if ($now_f - $begin_f > 1) {
1414 $begin_f = strtotime(date("Y-m-d H:i:s"));
1415 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1416 output($st_count . " stories found.");
1417 }
1418
1419 if ($st_count > 200) {
1420 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1421 output($st_count . " stories found.");
1422
1423 $now_ms = strtotime(date("Y-m-d H:i:s"));
1424 if ($now_ms - $begin_ms >= $delay) {
1425 // all fine
1426 } else {
1427 $counter3 = $delay - ($now_ms - $begin_ms);
1428 output("Starting " . $counter3 . " second(s) delay for bypassing Instagram limits.");
1429 do {
1430 output($counter3 . " second(s) left.");
1431 sleep(1);
1432 $counter3 -= 1;
1433 } while ($counter3 != 0);
1434 }
1435
1436 // Mark collected stories as seen
1437 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1438 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1439
1440 $st_count_seen = number_format($st_count, 0, '.', ' ');
1441 $counter2 += 1;
1442 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1443 output($st_count_seen . " stories marked as seen.");
1444
1445 output_clean("");
1446 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1447 output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1448 output_clean("");
1449
1450 // Initialize arrays and parameters again
1451 $stories = [];
1452 $st_count = 0;
1453 }
1454 }
1455 }
1456
1457 if (($st_count > 0) && $last && $data[$key]['max_id'] == null) {
1458 // Mark collected stories as seen
1459 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1460
1461 $st_count_seen = number_format($st_count, 0, '.', ' ');
1462 $counter2 += 1;
1463 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1464 output($st_count_seen . " stories marked as seen.");
1465 output_clean("");
1466 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1467 output_clean("");
1468
1469 // Initialize arrays and parameters again
1470 $stories = [];
1471 $st_count = 0;
1472 }
1473 } catch (\InstagramAPI\Exception\NetworkException $e) {
1474 output("We couldn't connect to Instagram at the moment. Trying again.");
1475 sleep(7);
1476 $index_new -= 13;
1477 continue;
1478 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1479 output("Instagram sent us empty response. Trying again.");
1480 sleep(7);
1481 $index_new -= 13;
1482 continue;
1483 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1484 output("Please login again to your Instagram account. Login required.");
1485 run($ig);
1486 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1487 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1488 run($ig);
1489 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1490 output("Please go to Instagram website or mobile app and pass checkpoint!");
1491 run($ig);
1492 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1493 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
1494 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1495 run($ig);
1496 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1497 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1498 run($ig);
1499 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1500 output("Access to Instagram API restricted for spam behavior or otherwise abusing.");
1501 run($ig);
1502 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1503 output("Throttled by Instagram because of too many API requests.");
1504 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1505 run($ig);
1506 } catch (Exception $e){
1507 output($e->getMessage());
1508 sleep(7);
1509 }
1510
1511 $index_old = $index_new + 1;
1512
1513 } while ($last == false);
1514
1515 // Check is $max_id is null
1516 if ($data[$key]['max_id'] == null) {
1517 output_clean("All stories of @" . $d['username'] . "'s followers successfully seen.");
1518 unset($data[$key]);
1519 continue;
1520 }
1521
1522 } catch (\InstagramAPI\Exception\NetworkException $e) {
1523 sleep(7);
1524 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1525 sleep(7);
1526 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1527 output("Please login again to your Instagram account. Login required.");
1528 run($ig);
1529 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1530 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1531 run($ig);
1532 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1533 output("Please go to Instagram website or mobile app and pass checkpoint!");
1534 run($ig);
1535 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1536 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
1537 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1538 run($ig);
1539 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1540 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1541 run($ig);
1542 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1543 output("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
1544 run($ig);
1545 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1546 output("Throttled by Instagram because of too many API requests.");
1547 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1548 run($ig);
1549 } catch (Exception $e){
1550 output($e->getMessage());
1551 sleep(7);
1552 }
1553 }
1554 } while (!empty($data));
1555
1556 output_clean("All stories related to the targets seen. Starting the new loop.");
1557 output_clean("");
1558
1559 masslooking_v2($targets, $ig, $delay);
1560}
1561
1562/**
1563 * Send request
1564 * @param $url
1565 * @return mixed
1566 */
1567function request($url) {
1568 $ch = curl_init();
1569
1570 curl_setopt($ch, CURLOPT_URL, $url);
1571 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1572 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1573 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1574
1575 $return = curl_exec($ch);
1576
1577 curl_close($ch);
1578
1579 return $return;
1580}
1581
1582/**
1583 * Get IP details
1584 */
1585function ip_details() {
1586 try {
1587 $json = request("http://www.geoplugin.net/json.gp");
1588 } catch (Exception $e){
1589 $msg = $e->getMessage();
1590 output($msg);
1591 run($ig);
1592 }
1593 $details = json_decode($json);
1594 return $details;
1595}
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646/**
1647 * Validate license
1648 * @param $license_key
1649 * @return string
1650 */
1651function activate_license($license_key, $ig) {
1652 // // Get user IP info
1653 // $details = ip_details();
1654 // $ip = $details->geoplugin_request ? $details->geoplugin_request : "not-detected";
1655
1656 // // Verify license key with Nextpost.tech Licensing API
1657 // $license = "invalid";
1658 // if ($license_key) {
1659 // $url = 'https://nextpost.tech/?edd_action=activate_license&item_id=14961&license=' . $license_key . '&url=' . 'IP-' . $ip;
1660 // try {
1661 // $license_resp = request($url);
1662 // } catch (Exception $e){
1663 // $msg = $e->getMessage();
1664 // output($msg);
1665 // run($ig);
1666 // }
1667 // $license_json = json_decode($license_resp);
1668 // $license = isset($license_json->license) ? $license_json->license : "invalid";
1669 // } else {
1670 // // License Key not set
1671 // $license_key = null;
1672 // }
1673
1674 return true;
1675
1676 return $license;
1677}
1678
1679?>