java - Java中使用Instagram4j连接Instagram的问题

标签 java instagram

我正在尝试登录,在本地主机中没问题,但在服务(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/

相关文章:

java - 您如何模拟您尝试使用 JUnit + Mockito 进行单元测试的服务中使用的类

java - hibernate 版本 4 jar,maven 依赖项不在存储库中 - 好吧,它在存储库中,但我的存储库是错误的

ios - 如何将图像从我的应用程序分享到 Instagram

java - 使用 Java 1.6 接收包含 ISO 8601 格式日期的字符串的 ParseException

java - Android MD5 问题计算 MD5,缺少字符

ios - 从 UIDocumentInteractionController 选择 App 会抛出 "LaunchServices: invalidationHandler called"错误

javascript - 从公共(public) Instagram 主题标签获取图像

php - 通过 Instagram API 确定媒体删除的有效方法

instagram - 将范围添加到 Instagram 应用程序?

java - 在 Java 中,有没有一种方法可以跟踪变量、方法或类是在堆还是栈中创建的?