我正在尝试登录,在本地主机中没问题,但在服务(AWS)中,它没有登录。 我有一个登录方法,并将登录信息保存在 cookie.txt 文件中,如果我需要登录,请找到不再登录的 cookie 文件
我的登录代码如下:
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,**
最佳答案
关于java - Java中使用Instagram4j连接Instagram的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60711488/