ErrorxCode / JxInsta

An object-oriented reverse engineered instagram web API made in Java. Now build bots, scrap data, create instagram apps, and a lot more in your favourite language
Apache License 2.0
22 stars 5 forks source link

Handle is missing error when posting picture. #5

Closed Nath5 closed 3 weeks ago

Nath5 commented 8 months ago

Error while trying to post a picture. Error message and example code are below.

Library Version: JxInsta-v1.0-beta-2.jar Java Version: 17

{"debug_info":{"retriable":false,"type":"ProcessingFailedError","message":"{\"message\":\"Handle is missing.\",\"status\":\"fail\"}"}}

 val insta = JxInsta("myhandle", "mypassword", JxInsta.LoginType.BOTH_WEB_AND_APP_AUTHENTICATION)
    val url = URL("PATH_TO_IMAGE")
    val imageData: ByteArray = url.readBytes()
    insta.postPicture(
        ByteArrayInputStream(imageData),
        "This is a caption",
        false
    )
Nath5 commented 8 months ago

After some more digging it looks like the problem is more specifically in this function:


    public static String uploadPicture(@NotNull InputStream in, @NotNull String token) throws IOException {
        String uploadId = Long.toString(Math.abs((new Random()).nextLong()), 36);
        byte[] bytes = new byte[in.available()];
        in.read(bytes);
        boolean isCookie = token.contains("sessionid");
        Request.Builder uploadReq = (new Request.Builder()).url("https://i.instagram.com/rupload_igphoto/JxInsta_upload_" + uploadId).post(RequestBody.create(bytes)).headers(Headers.of(Constants.BASE_HEADERS)).addHeader("x-instagram-rupload-params", "{\"media_type\":1,\"upload_id\":\"" + uploadId + "\"}").addHeader("x-entity-length", String.valueOf(bytes.length)).addHeader("x-entity-name", "JxInsta_upload_" + uploadId).addHeader("x-entity-type", "image/jpeg").addHeader("offset", String.valueOf(0)).removeHeader("content-type").addHeader(isCookie ? "cookie" : "authorization", token).addHeader("content-type", "application/octet-stream");
        Response res = client.newCall(uploadReq.build()).execute();
        if (res.isSuccessful()) {
            return uploadId;
        } else {
            System.out.println(res.body().string());
            throw new IOException("Failed to upload picture");
        }
    }
ErrorxCode commented 8 months ago

Thanks for figuring it out :) I will look into this soon and will fix at ASAP.

ErrorxCode commented 7 months ago

I just tested and it's perfectly working fine. I think the problem is in your image input-stream. Try doing same with a local image using FileInputStream