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

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

Go to download

this is library for working with instagram without using instagram api. this library use instagram web browser

The newest version!
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 javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
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();
        Ason login = insta.login("alializadehmehr", "peter6220");

//        Insta insta = new Gson().fromJson("{\"cookie\":{\"ig_cb\":\"1\",\"ds_user_id\":\"8171223301\",\"mid\":\"W0OPlQAEAAGHxpokwbm3H12QkpLW\",\"sessionid\":\"IGSCab4e3ceca7497750994447b2781496ce1b0063580603565cb1ce21663c4775ed%3ABu2lzMBtgq0w6MyDf7C9w1Fl8duW4uBn%3A%7B%22_auth_user_id%22%3A8171223301%2C%22_auth_user_backend%22%3A%22accounts.backends.CaseInsensitiveModelBackend%22%2C%22_auth_user_hash%22%3A%22%22%2C%22_platform%22%3A4%2C%22_token_ver%22%3A2%2C%22_token%22%3A%228171223301%3ANSI1Eh9TxSwcxSgLx2wsOgteQgHZcG2U%3Aea907b0c98e1f16dd2a7ace8371ea526d30988129e145897d4d477f35afbbd64%22%2C%22last_refreshed%22%3A1531154325.757017374%7D\",\"csrftoken\":\"gLVo4u0J3XeKdFBxOAIiYES4tFRRBzhC\",\"rur\":\"FTW\",\"mcd\":\"3\"},\"login\":true,\"username\":\"alializadehmehr\",\"password\":\"peter6220\",\"csrf\":\"gLVo4u0J3XeKdFBxOAIiYES4tFRRBzhC\",\"rhx_gis\":\"95d9e71a99e90cb3bc250e00a90d39a4\",\"userAgent\":\"Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20130328 Firefox/21.0\",\"ip\":\"\",\"port\":0,\"rollOutHash\":\"4e47b54bd7d8\",\"checkpointUrl\":\"\"}\n", Insta.class);
//        System.out.println(new Gson().toJson(insta));
        ArrayList seenIds = new ArrayList<>();
        while (true) {
            SuggestedResponse sr = insta.getSuggestedUser(seenIds);
            System.out.println(seenIds.size() + ":" + sr.getUserIds().size() + "---------------------");
            seenIds.addAll(sr.getUserIds());
            sr.getSuggestedUsers().forEach(user -> {
                if(user.getDescription().equals("In your contacts"))
                System.out.println(user.getUsername() + " : " + user.getFullname());
            });
            Thread.sleep(5000);
        }
//        User user = insta.getUser("Olivia.gr1990");
//        System.out.println(user.getInstaId());
//        System.out.println(insta.getYourSelf().getInstaId());
//        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