JxInsta icon indicating copy to clipboard operation
JxInsta copied to clipboard

Handle is missing error when posting picture.

Open Nath5 opened this issue 1 year ago • 3 comments

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 avatar Mar 30 '24 16:03 Nath5

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");
        }
    }

Nath5 avatar Apr 02 '24 13:04 Nath5

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

ErrorxCode avatar Apr 02 '24 16:04 ErrorxCode

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

ErrorxCode avatar Apr 03 '24 20:04 ErrorxCode