All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ir.sadeghpro.insta.client.Test Maven / Gradle / Ivy

package ir.sadeghpro.insta.client;

import com.afollestad.ason.Ason;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

    public static void main(String[] args) throws Exception {

//        Insta insta = new Insta("", "");

//        Insta insta = new Insta();
//        System.out.println(insta.getHashTag("star").getProfilePicUrl());
//

        Insta insta = new Insta();
        Ason json = insta.login("maryam.sli72", "ali112200");
        if (json.getString("status", "").equals("fail")) {
            if (json.has("checkpoint_url")) {
                json = insta.getChallenge();
                System.out.println(json.toString());
                insta.sendSecurityCode("1");
                System.out.println("Enter your username: ");
                Scanner scanner = new Scanner(System.in);
                String username = scanner.nextLine();
                insta.submitSecurityCode(username);
                System.out.println(insta.isLogin());
                insta.follow("reza.omovat");
            }
        }


//        try {
//            Insta insta = new Insta();
//            Ason json = insta.login("maryam.sli72","ali112200");
//            String status = json.getString("status","");
//            assert status != null;
//            if(status.equals("fail")){
//                if(json.has("checkpoint_url")){
//                    String url = S.URL + "challenge" + json.getString("checkpoint_url").replace("challenge/","");
//                    System.out.println(url);
//                    Connection.Response r = Jsoup.connect(url)
//                            .method(Connection.Method.GET).header("X-CSRFToken",insta.getCsrf()).ignoreHttpErrors(true)
//                            .header("X-Instagram-AJAX",insta.getRollOutHash()).cookies(insta.getCookie()).userAgent(insta.getUserAgent()).ignoreContentType(true).execute();
////                    Ason object = new Ason(r.body());
//                    System.out.println("---------------");
//                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
//                    System.out.println("---------------");
//                    for (Map.Entry entry : r.cookies().entrySet()) {
////                        System.out.println(entry.getKey() +":"+entry.getValue() +"::::::::::::");
//                        if (entry.getValue().isEmpty() || entry.getValue().equals("\"\"")) {
//                            insta.getCookie().remove(entry.getKey());
//                        } else {
//                            insta.getCookie().put(entry.getKey(), entry.getValue());
//                        }
//                    }
//                    System.out.println("---------------");
//                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
//                    System.out.println("---------------");
////                    if(object.has("fields.phone_number"))
////                    r = Jsoup.connect(S.URL + "challenge/reset" + json.getString("checkpoint_url").replace("challenge/",""))
////                            .method(Connection.Method.POST).data("choice","0").cookies(insta.getCookie()).header("X-CSRFToken",insta.getCsrf())
////                            .header("X-Instagram-AJAX",insta.getRollOutHash()).userAgent(insta.getUserAgent()).ignoreContentType(true).execute();
////
////                    System.out.println(r.body());
//////                    Thread.sleep(1000);
//////                    System.out.println("---------------");
//////                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
////                    for (Map.Entry entry : r.cookies().entrySet()) {
////                        if (entry.getValue().isEmpty() || entry.getValue().equals("\"\"")) {
////                            insta.getCookie().remove(entry.getKey());
////                        } else {
////                            insta.getCookie().put(entry.getKey(), entry.getValue());
////                        }
////                    }
//////                    System.out.println("---------------");
//////                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
//////                    System.out.println("---------------");
//
//                    Map headers = new HashMap<>();
//
//                    headers.put("origin", "https://www.instagram.com");
//                    headers.put("Host", "www.instagram.com");
//                    headers.put("Content-Type", "application/x-www-form-urlencoded");
//                    headers.put("X-CSRFToken", insta.getCsrf());
//                    headers.put("X-Instagram-AJAX", insta.getRollOutHash());
//                    headers.put("X-Requested-With", "XMLHttpRequest");
//                    headers.put("Accept", "*/*");
//                    headers.put("Accept-Encoding", "gzip, deflate, br");
//                    headers.put("Accept-Language", "en-US,en;q=0.9");
//                    headers.put("Pragma","no-cache");
//                    headers.put("DNT","1");
////                    Form form = new Form();
////                    form.add("security_code",username);
////                    Bridge.post(url).body(form
//                    r = Jsoup.connect(url).headers(headers).referrer(url).method(Connection.Method.POST).data("choice","1").cookies(insta.getCookie())
//                            .userAgent(insta.getUserAgent()).ignoreContentType(true).ignoreHttpErrors(true).execute();
//                    System.out.println(r.body());
//
//                    System.out.println("Enter your username: ");
//                    Scanner scanner = new Scanner(System.in);
//                    String username = scanner.nextLine();
//
////                    Form form = new Form();
////                    form.add("security_code",username);
////                    Bridge.post(url).body(form
//                    r = Jsoup.connect(url).headers(headers).referrer(url).method(Connection.Method.POST).data("security_code",username).cookies(insta.getCookie())
//                            .userAgent(insta.getUserAgent()).ignoreContentType(true).ignoreHttpErrors(true).execute();
//                    System.out.println(r.body());
//                    json = new Ason(r.body());
//                    for (Map.Entry entry : r.cookies().entrySet()) {
//                        if (entry.getValue().isEmpty() || entry.getValue().equals("\"\"")) {
//                            insta.getCookie().remove(entry.getKey());
//                        } else {
//                            insta.getCookie().put(entry.getKey(), entry.getValue());
//                        }
//                    }
//                    System.out.println("---------------");
//                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
//                    System.out.println("---------------");
//                    r = Jsoup.connect(json.getString("location")).cookies(insta.getCookie()).execute();
//                    for (Map.Entry entry : r.cookies().entrySet()) {
//                        if (entry.getValue().isEmpty() || entry.getValue().equals("\"\"")) {
//                            insta.getCookie().remove(entry.getKey());
//                        } else {
//                            insta.getCookie().put(entry.getKey(), entry.getValue());
//                        }
//                    }
//                    System.out.println("---------------");
//                    insta.getCookie().forEach((k,v)-> System.out.println(k+":"+v));
//                    System.out.println("---------------");
//                }
//            }
//            System.out.println(insta.isLogin());
//            System.out.println(insta.getFollowers(insta.getUser("selenagomez").getInstaId()).getJson());
//            System.out.println(insta.getYourSelf(true));
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy