postaddictme / instagram-java-scraper

Instagram Java Scraper. Get account information, photos, videos and comments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

java.lang.NullPointerException (ModelMapper.java:150) (Instagram.java:159)

GiorgosXou opened this issue · comments

commented

First of all thanks you for developing this library, second of all I am really confused trying to make it work (as a kinda noobie that i am), (pls make another release so we can use it with maven [because jitpack with master-SNAPSHOT doesnt work for me at least now that i am posting this issue])

[General] :

App.java

package app;

import me.postaddict.instagram.scraper.interceptor.ErrorInterceptor;
import me.postaddict.instagram.scraper.cookie.DefaultCookieJar;
import me.postaddict.instagram.scraper.interceptor.UserAgents;
import me.postaddict.instagram.scraper.cookie.CookieHashSet;
import me.postaddict.instagram.scraper.AuthenticatedInsta;
import me.postaddict.instagram.scraper.model.Account;
import me.postaddict.instagram.scraper.interceptor.*;
import me.postaddict.instagram.scraper.Instagram;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.OkHttpClient;


public final class App {
    private App() {}
    
    private static AuthenticatedInsta client;

    public static void main(String[] args) throws Exception {
    
        Credentials credentials = new Credentials() ;
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        
       loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);

        OkHttpClient httpClient = new OkHttpClient.Builder()
                .addNetworkInterceptor(loggingInterceptor)
                .addInterceptor(new FakeBrowserInterceptor(UserAgents.WIN10_CHROME))
                .addInterceptor(new ErrorInterceptor())
                .cookieJar(new DefaultCookieJar(new CookieHashSet()))
                .build();

        client = new Instagram(httpClient);
        client.basePage();
        client.login(credentials.getLogin(), credentials.getPassword());
        client.basePage();

        Account account = client.getAccountByUsername("giorgos.xou"); // Issue.
        //System.out.println(account);
    }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>app</groupId>
  <artifactId>app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>5.6.0</junit.version>
    <maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
    <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
    <checkstyle.version>8.29</checkstyle.version>
    <checkstyle-rules.version>4.0.1</checkstyle-rules.version>
    <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
    <jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
    <maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
    <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
    <!-- JaCoCo thresholds. Increase gradually as you add tests. -->
    <jacoco.unit-tests.limit.instruction-ratio>0%</jacoco.unit-tests.limit.instruction-ratio>
    <jacoco.unit-tests.limit.branch-ratio>0%</jacoco.unit-tests.limit.branch-ratio>
    <jacoco.unit-tests.limit.class-complexity>20</jacoco.unit-tests.limit.class-complexity>
    <jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>LATEST</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>logging-interceptor</artifactId>
      <version>LATEST</version>
    </dependency>

    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>org.eclipse.persistence.moxy</artifactId>
      <version>2.6.9</version>
    </dependency>

    <dependency>
      <groupId>com.github.igor-suhorukov</groupId>
      <artifactId>dom-transformation</artifactId>
      <version>LATEST</version>
    </dependency>
        
    <dependency>
      <groupId>app</groupId>
      <artifactId>instagramscraper</artifactId>
      <scope>system</scope>
      <version>0.0.1</version>
      <systemPath>C:/.../instagram-java-scraper-master/build/libs/instagramscraper-scraper-0.0.1.jar</systemPath>
    </dependency>
 
  </dependencies>

  <build>
...

[Issue]

Normal Console Output:

Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: --> GET https://www.instagram.com/giorgos.xou/?__a=1 http/1.1
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Accept: */*
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Accept-Language: ja,en-US;q=0.7,en;q=0.3
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: DNT: 1
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Host: www.instagram.com
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Connection: Keep-Alive
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Accept-Encoding: gzip
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Cookie: csrftoken=...; mid=...; shbts=...; sessionid=...; shbid=6792; ds_user_id=...; rur=ASH; ig_did=...
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: --> END GET
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: <-- 200 OK https://www.instagram.com/giorgos.xou/?__a=1 (711ms)
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Content-Type: application/json; charset=utf-8
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: x-robots-tag: noindex
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Vary: Accept-Language, Cookie, Accept-Encoding
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Content-Language: ja
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Date: Wed, 10 Feb 2021 19:02:04 GMT
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Content-Encoding: gzip
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Strict-Transport-Security: max-age=31536000
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Cache-Control: private, no-cache, no-store, must-revalidate
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Pragma: no-cache
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: Expires: Sat, 01 Jan 2000 00:00:00 GMT
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: X-Frame-Options: SAMEORIGIN
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: content-security-policy: report-uri https://www.instagram.com/security/csp_report/; default-src 'self' https://www.instagram.com; img-src data: blob: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com https://*.facebook.com; font-src data: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com; media-src 'self' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src 'self' https://www.instagram.com; script-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' https://*.www.instagram.com https://www.instagram.com 'unsafe-inline'; connect-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://*.cdninstagram.com https://api.instagram.com https://i.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src 'self' blob: https://www.instagram.com; frame-src 'self' https://instagram.com https://www.instagram.com https://*.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com; object-src 'none'; upgrade-insecure-requests
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: cross-origin-embedder-policy-report-only: require-corp;report-to="coep"
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: report-to: {"group": "coep", "max_age": 86400, "endpoints": [{"url": "/security/coep_report/"}]},{"group": "coop", "max_age": 86400, "endpoints": [{"url": "/security/coop_report/"}]}
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: origin-trial: ...
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: cross-origin-opener-policy: same-origin-allow-popups;report-to="coop"
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: X-Content-Type-Options: nosniff
Φεβ 10, 2021 9:02:04 ΜΜ okhttp3.internal.platform.Platform log
INFO: X-XSS-Protection: 0
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: x-ig-push-state: c2
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: x-aed: 38
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Access-Control-Expose-Headers: X-IG-Set-WWW-Claim
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Set-Cookie: csrftoken=...; Domain=.instagram.com; expires=Wed, 09-Feb-2022 19:02:04 GMT; Max-Age=31449600; Path=/; Secure
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Set-Cookie: rur=FRC; Domain=.instagram.com; HttpOnly; Path=/; Secure
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Set-Cookie: ds_user_id=11211987521; Domain=.instagram.com; expires=Tue, 11-May-2021 19:02:04 GMT; Max-Age=7776000; Path=/; Secure
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: X-FB-TRIP-ID: 1679558926
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Alt-Svc: h3-29=":443"; ma=3600,h3-27=":443"; ma=3600
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Connection: keep-alive
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: Content-Length: 17692
Φεβ 10, 2021 9:02:05 ΜΜ okhttp3.internal.platform.Platform log
INFO: <-- END HTTP

Then Suddenly:

Exception in thread "main" java.lang.NullPointerException
        at me.postaddict.instagram.scraper.mapper.ModelMapper.mapAccount(ModelMapper.java:150)
        at me.postaddict.instagram.scraper.Instagram.getAccountByUsername(Instagram.java:159)
        at app.App.main(App.java:44)

Any Idea? Thanks in advance.