JxInsta icon indicating copy to clipboard operation
JxInsta copied to clipboard

Updates on this library?

Open nicecraftz opened this issue 1 year ago • 10 comments

Hello, are there any updates on this library? ì I have seen it has been called a continuation of Instagram4J but I cannot make it work

https://gist.github.com/nicecraftz/287ffd4e3437ac8b96f26cd86d4a0455

I am getting this error just when creating the instance of JxInsta with valid credentials. Exception in thread "main" java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 0. at kotlin.collections.EmptyList.get(Collections.kt:36) at kotlin.collections.EmptyList.get(Collections.kt:24) at com.errorxcode.jxinsta.Utils.getCrsf(Utils.java:100) at com.errorxcode.jxinsta.JxInsta.<init>(JxInsta.java:71) at it.alessandrocalista.Main.main(Main.java:22)

nicecraftz avatar Nov 22 '24 23:11 nicecraftz

Is it happening only in WEB_AUTHENTICATION mode?

ErrorxCode avatar Nov 25 '24 12:11 ErrorxCode

Really sorry for the no reply about this issue, will try tomorrow if i happen to remember it, lol.

sorry again.

nicecraftz avatar Dec 13 '24 00:12 nicecraftz

It's okey, lemme know

ErrorxCode avatar Feb 02 '25 21:02 ErrorxCode

It's okey, lemme know

totally forgot about this once again, i will try in the morning, just put it into my calendar to remember it, lol.

nicecraftz avatar Feb 02 '25 21:02 nicecraftz

Hallo, sorry for the long awaited response

public static void main(String[] args) {
        try {
            JxInsta insta = new JxInsta(
                    "#####",
                    "#####",
                    JxInsta.LoginType.BOTH_WEB_AND_APP_AUTHENTICATION
            );
            File file = new File("test.jpg");
            insta.uploadStory(file);
        } catch (IOException | InstagramException e) {
            throw new RuntimeException(e);
        }
        System.out.println("Hello, World!");
    }

This is my current snippet, it should publish a story with the following test.jpg image but instead its giving me out this error.

Exception in thread "main" java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 0.
	at kotlin.collections.EmptyList.get(Collections.kt:36)
	at kotlin.collections.EmptyList.get(Collections.kt:24)
	at com.errorxcode.jxinsta.Utils.getCrsf(Utils.java:100)
	at com.errorxcode.jxinsta.JxInsta.<init>(JxInsta.java:71)
	at com.errorxcode.jxinsta.JxInsta.<init>(JxInsta.java:77)
	at it.alessandrocalista.instagram.Main.main(Main.java:12)

nicecraftz avatar Feb 05 '25 11:02 nicecraftz

Change the LoginType to WEB_AUTH and try again, after that change it to MOBILE_AUTH and try again. Let me know the error in both cases

ErrorxCode avatar Feb 08 '25 11:02 ErrorxCode

I also get the same issue (exact same stack). I've tried all available auth types.

cboldon avatar Apr 01 '25 17:04 cboldon

Alright, Please wait for the update!

ErrorxCode avatar Apr 02 '25 10:04 ErrorxCode

Its the Utils.getCrsf() function just replace it with

protected static String getCrsf() throws IOException {
        Request request = new Request.Builder()
                .url("https://www.instagram.com/")
                .addHeader("user-agent", Constants.WEB_USER_AGENT)
                .addHeader("accept", "*/*")
                .addHeader("accept-language", "en-US,en;q=0.9")
                .addHeader("x-requested-with", "XMLHttpRequest")
                .get()
                .build();
        try (Response response = client.newCall(request).execute()) {
            List<String> cookies = response.headers("Set-Cookie");
            for (String cookie : cookies) {
                if (cookie.startsWith("csrftoken=")) {
                    return cookie.split(";")[0].split("=")[1];
                }
            }
            throw new IOException("csrftoken not found in cookies");
        }
    }

But I have already sent the main author a request to merge my enhancements for this library.

felixgodo avatar Jun 02 '25 19:06 felixgodo

Thank you for drawing attention to the issue. I'll counter this in the new release (Coming soon)

ErrorxCode avatar Jun 09 '25 22:06 ErrorxCode