Coder Social home page Coder Social logo

ankurrai1 / instagram4android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kolyall/instagram4android

1.0 0.0 0.0 376 KB

:camera: Android library for accessing Instagram's private API with Facebook login support

License: MIT License

Java 100.00%

instagram4android's Introduction

Instagram4Android

PRs Welcome Android Arsenal

Drawing

This library directly talks to the private Instagram API, anything (well quite a lot) you can do on the IG app you can replicate with this library. You also bypass the public API's rate limits.

Support me

Any support, money or otherwise, is greatly appreciated and motivates me to keep this library alive!  Also as a student beer money is always appreciated ;) !

Bitcoin: 1BFLxaSGkk9DRjx7WTg9NkcWtRUzF2Z7qe

Credit

This was originally a port of a popular Java repository that provides access to Instagrams' private API. This has been changed around to use OkHttp and various other fixes have been made to make it work with Android. I will be updating this with more endpoints and so on as time goes on.

Project not in any way afilliated with Instagram.

Fair Use

Do NOT use this to spam anyone at all.
Do NOT use this for any illegal activities.

Installation

Add the following to your root build.gradle file:

allprojects {
    repositories {
	...
	maven { url 'https://jitpack.io' }
    }
}

Then add the following to your app level build.gradle file, use the version number of the latest release:

dependencies {
    compile 'com.github.charlieAndroidDev:Instagram4Android:$VERSION'
}

Make sure your min sdk is 19 or higher in your app-level build.gradle, like this.

Instructions

Login

Instagram4Android instagram = Instagram4Android.builder().username(username).password(password).build();
instagram.setup();
instagram.login();

You must call setup() before login() otherwise an exception is thrown.

Below is my implementation of logging in to Instagram in my presenter (MVP) using RxJava2 and RxAndroid:

private void loginToInstagram(final String username, final String password) {

        Instagram4Android instagram = Instagram4Android.builder().username(username).password(password).build();

        attemptLogin(instagram, username, password)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(instagramLoginResult -> {

                    if(instagramLoginResult.getStatus().equals(view.getStringResource(R.string.login_success))) {
                        view.loginFinished(instagram);
                    } else {
                        view.loginFailed(instagramLoginResult.getMessage());
                    }

                });

    }

private Observable<InstagramLoginResult> attemptLogin(final Instagram4Android instagram) {

        Observable<InstagramLoginResult> observable = Observable.create(observableEmitter -> {

            instagram.setup();
            observableEmitter.onNext(instagram.login());

        });

        return observable;

    }       

The String resource R.string.login_success is "ok".

Login with Facebook

This is in beta right now hence the weird login flow.

Instagram4Android instagram = Instagram4Android.builder().username("").password(FACEBOOK_ACCESS_TOKEN).build();
instagram.setup();
InstagramLoginResult result = instagram.loginFb();

After that, the rest is the same.

Get user info

InstagramSearchUsernameResult result = instagram.sendRequest(new InstagramSearchUsernameRequest("example_username"));
InstagramUser user = result.getUser();

Send the request using your Instagram4Android instance, and then call getUser() on the result. Now poke around and see what info you can get from that user object.

Follow user

instagram.sendRequest(new InstagramFollowRequest(user.getPk()));

Very simple.

Get stories (the ones you see at the top of your homepage)

InstagramReelsTrayFeedResult result = instagram4Android.sendRequest(new InstagramReelsTrayRequest());
List<InstagramStoryTray> trays = result.getTray();

trays now contains a list of InstagramStoryTray which, for the first few elements, will have a list of story items and info about the user whose story it is. After the first 3-5 elements the list of story items will be null (We'll fix that below).

To get the rest of the story items for everyone in your reel tray do this:

InstagramReelsTrayFeedResult result = instagram4Android.sendRequest(new InstagramReelsTrayRequest());
List<InstagramStoryTray> trays = result.getTray();

List<InstagramUserStoryFeedResult> userStories = new ArrayList<>();
for(InstagramStoryTray tray : trays) {
    if(tray != null) {
        userStories.add(instagram4Android.sendRequest(new InstagramUserStoryFeedRequest("" + tray.getUser().getPk())));
    }
}

// To print the url's of the first items in everyones story do this
for(InstagramUserStoryFeedResult story : userStories) {
    if(story.getReel() == null) {
        System.out.println("Null check for safety, hardly ever null");
    } else {
        System.out.println(story.getReel().getItems().get(0).getImage_versions2().getCandidates().get(0).getUrl());
    }
}

instagram4android's People

Contributors

charlie-niekirk avatar cagdasc avatar federicoponzi avatar quiquelhappy avatar

Stargazers

Savaş ADAR avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.