标题翻译
Problem with the connection with Instagram using Instagram4j in Java
问题
以下是翻译好的部分:
我正在尝试进行登录,在本地主机上是可以的,但在服务器(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 {
// 从.txt文件中读取Cookie
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(System.getProperty("user.dir") + FILE_COOKIES));
CookieStore cookieStore = (CookieStore) ois.readObject();
ois.close();
// 验证会话
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 : 从 {"message": "login_required", "error_title": "You've Been Logged Out", "error_body": "Please log back in.", "logout_reason": 2,**
英文翻译
I am trying of do login, in localhost is OK, but in the serve (AWS), It isn't doing login.
I have a method for do login and save the login in a cookie.txt file, If I need the login, find the cookie file for don't do login again
My code for do login is the next:
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;
}
For verify the cookies:
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;
}
For call the method:
Instagram4j instagramLogin = Instagram4j.builder().username(INSTAGRAM_USERNAME).password(INSTAGRAM_PASSWORD).build();
Instagram4j instagram = (checkLogin(instagramLogin) == null) ? login(instagramLogin) : checkLogin(instagramLogin);
The error in the serve is this:
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,**
答案1
得分: 0
你需要完成验证过程
https://github.com/instagram4j/instagram4j/pull/358
英文翻译
You need to complete the verification process
专注分享java语言的经验与见解,让所有开发者获益!
评论