Search in sources :

Example 1 with DefaultCookieJar

use of me.postaddict.instagram.scraper.cookie.DefaultCookieJar in project instagram-java-scraper by postaddictme.

the class AnonymousInstaTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
    client = new Instagram(httpClient);
    client.basePage();
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) UserAgentInterceptor(me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) BeforeClass(org.junit.BeforeClass)

Example 2 with DefaultCookieJar

use of me.postaddict.instagram.scraper.cookie.DefaultCookieJar in project instagram-java-scraper by postaddictme.

the class AuthenticatedInstaTest method testLoginWithInvalidCredentials.

@Test(expected = InstagramAuthException.class)
public void testLoginWithInvalidCredentials() throws Exception {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
    Instagram instagramClient = new Instagram(httpClient);
    instagramClient.basePage();
    instagramClient.login("1", "2");
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) UserAgentInterceptor(me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Test(org.junit.Test)

Example 3 with DefaultCookieJar

use of me.postaddict.instagram.scraper.cookie.DefaultCookieJar in project instagram-java-scraper by postaddictme.

the class AuthenticatedInstaTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Credentials credentials = new Credentials();
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
    client = new Instagram(httpClient);
    client.basePage();
    client.login(credentials.getLogin(), credentials.getPassword());
    client.basePage();
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) UserAgentInterceptor(me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) BeforeClass(org.junit.BeforeClass)

Example 4 with DefaultCookieJar

use of me.postaddict.instagram.scraper.cookie.DefaultCookieJar in project instagram-java-scraper by postaddictme.

the class MultiThreadTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new UserAgentInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
    client = new Instagram(httpClient);
    client.basePage();
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) UserAgentInterceptor(me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) BeforeClass(org.junit.BeforeClass)

Example 5 with DefaultCookieJar

use of me.postaddict.instagram.scraper.cookie.DefaultCookieJar in project instagram-java-scraper by postaddictme.

the class InstagramFactory method getAuthenticatedInstagramClient.

public static Instagram getAuthenticatedInstagramClient(String login, String password, String userAgent) throws IOException {
    OkHttpClient httpClient = new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor(userAgent)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
    Instagram client = new Instagram(httpClient);
    client.basePage();
    client.login(login, password);
    client.basePage();
    return client;
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) UserAgentInterceptor(me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar)

Aggregations

CookieHashSet (me.postaddict.instagram.scraper.cookie.CookieHashSet)5 DefaultCookieJar (me.postaddict.instagram.scraper.cookie.DefaultCookieJar)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 UserAgentInterceptor (me.postaddict.instagram.scraper.interceptor.UserAgentInterceptor)5 OkHttpClient (okhttp3.OkHttpClient)5 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)1