在Java中使用Instagram4j连接Instagram时出现问题
我正在尝试登录,在localhost中是可以的,但是在serve(AWS)中,它没有登录。 我有一个做登录的方法,并将登录保存在cookie.txt文件中,如果我需要登录,请找到不再做登录的cookie文件 我的do登录代码如下所示:在Java中使用Instagram4j连接Instagram时出现问题,java,instagram,Java,Instagram,我正在尝试登录,在localhost中是可以的,但是在serve(AWS)中,它没有登录。 我有一个做登录的方法,并将登录保存在cookie.txt文件中,如果我需要登录,请找到不再做登录的cookie文件 我的do登录代码如下所示: protected Instagram4j login(Instagram4j instagram){ try { instagram.setup(); instagram.login(); File cookiesFile = ne
protected Instagram4j login(Instagram4j instagram){
try {
instagram.setup();
instagram.login();
File cookiesFile = new File(System.getProperty("user.dir") + FILE_COOKIES);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cookiesFile));
oos.writeObject(instagram.getCookieStore());
oos.close();
} catch (IOException e){
e.printStackTrace();
}
return instagram;
}
要验证cookie,请执行以下操作:
protected Instagram4j checkLogin(Instagram4j instagram){
Instagram4j instagram2 = null;
try {
// Open de cookies in the .txt
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(System.getProperty("user.dir") + FILE_COOKIES));
CookieStore cookieStore = (CookieStore) ois.readObject();
ois.close();
// Verify the session
instagram2 = Instagram4j.builder().username(INSTAGRAM_USERNAME)
.password(INSTAGRAM_PASSWORD)
.uuid(instagram.getUuid())
.cookieStore(cookieStore)
.build();
instagram2.setup();
} catch (IOException e) {
e.getMessage();
} catch (ClassNotFoundException e) {
e.getMessage();
}
return instagram2;
}
要调用该方法,请执行以下操作:
Instagram4j instagramLogin = Instagram4j.builder().username(INSTAGRAM_USERNAME).password(INSTAGRAM_PASSWORD).build();
Instagram4j instagram = (checkLogin(instagramLogin) == null) ? login(instagramLogin) : checkLogin(instagramLogin);
发球中的错误是:
2020-03-16 12:02:36.640 INFO 18541 --- [task-scheduler-10] o.brunocvcunha.instagram4j.Instagram4j : Setup...
2020-03-16 12:02:36.640 INFO 18541 --- [task-scheduler-10] o.brunocvcunha.instagram4j.Instagram4j : Device ID is: android-547cbdeb2f1634d4, random id: c8c30455-72fd-4a0e-a396-5c5d2e422092
2020-03-16 12:02:36.641 INFO 18541 --- [task-scheduler-10] o.brunocvcunha.instagram4j.Instagram4j : Setup...
2020-03-16 12:02:36.641 INFO 18541 --- [task-scheduler-10] o.brunocvcunha.instagram4j.Instagram4j : Device ID is: android-547cbdeb2f1634d4, random id: fad1e2c1-61e8-4c13-a642-320b402ce74a
2020-03-16 12:02:36.641 INFO 18541 --- [task-scheduler-10] o.brunocvcunha.instagram4j.Instagram4j : Sending request: org.brunocvcunha.instagram4j.requests.InstagramSearchUsernameRequest
**2020-03-16 12:02:36.973 INFO 18541 --- [task-scheduler-10] o.b.i.requests.InstagramRequest : Reading InstagramSearchUsernameResult from {"message": "login_required", "error_title": "You've Been Logged Out", "error_body": "Please log back in.", "logout_reason": 2,**
您需要完成验证过程
您需要完成验证过程