├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── me │ │ │ │ └── aravi │ │ │ │ └── instagramx │ │ │ │ └── sample │ │ │ │ ├── App.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── me │ │ │ └── aravi │ │ │ └── instagramx │ │ │ └── sample │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── me │ │ └── aravi │ │ └── instagramx │ │ └── sample │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── core ├── .gitignore ├── consumer-rules.pro ├── proguard-rules.pro ├── src │ ├── main │ │ ├── res │ │ │ ├── font │ │ │ │ └── bold.ttf │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ └── colors.xml │ │ │ ├── drawable │ │ │ │ ├── ic_round_arrow_back_ios_new_24.xml │ │ │ │ └── ic_round_keyboard_backspace_24.xml │ │ │ └── layout │ │ │ │ └── activity_insta_auth.xml │ │ ├── java │ │ │ └── me │ │ │ │ └── aravi │ │ │ │ └── instagramx │ │ │ │ ├── utils │ │ │ │ └── NetworkUtils.kt │ │ │ │ ├── beans │ │ │ │ ├── ShortAccount.kt │ │ │ │ ├── Post.kt │ │ │ │ └── Profile.kt │ │ │ │ ├── auth │ │ │ │ ├── interfaces │ │ │ │ │ └── ClientCallback.kt │ │ │ │ ├── clients │ │ │ │ │ ├── CustomChromeClient.kt │ │ │ │ │ └── CustomWebClient.kt │ │ │ │ ├── InstaAuth.java │ │ │ │ ├── InstaUser.java │ │ │ │ └── InstaAuthActivity.java │ │ │ │ ├── InstaConfig.kt │ │ │ │ ├── di │ │ │ │ └── InstagramModule.kt │ │ │ │ ├── api │ │ │ │ └── InstagramApi.kt │ │ │ │ └── InstagramX.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── me │ │ │ └── aravi │ │ │ └── instagramx │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── me │ │ └── aravi │ │ └── instagramx │ │ └── ExampleInstrumentedTest.java └── build.gradle ├── .idea ├── .gitignore ├── compiler.xml ├── vcs.xml ├── misc.xml └── gradle.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── .github └── FUNDING.yml ├── gradle.properties ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /core/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -keepclassmembers class me.aravi.instagramx.beans* { *; } 2 | -------------------------------------------------------------------------------- /core/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -keepclassmembers class me.aravi.instagramx.beans* { *;} 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | InstagramXSample 3 | -------------------------------------------------------------------------------- /core/src/main/res/font/bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/core/src/main/res/font/bold.ttf -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ASASCorp/instagramx-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /core/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0dp 4 | 1dp 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 14 20:42:49 IST 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/test/java/me/aravi/instagramx/sample/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.sample 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | maven { url 'https://jitpack.io' } 14 | } 15 | } 16 | rootProject.name = "InstagramXSample" 17 | include ':app' 18 | include ':core' 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /core/src/test/java/me/aravi/instagramx/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/utils/NetworkUtils.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.utils 2 | 3 | import android.content.Context 4 | import android.net.ConnectivityManager 5 | 6 | object NetworkUtils { 7 | fun isNetworkAvailable(context: Context): Boolean { 8 | val connectivityManager = 9 | context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager 10 | val activeNetworkInfo = connectivityManager.activeNetworkInfo 11 | return activeNetworkInfo != null && activeNetworkInfo.isConnected 12 | } 13 | } -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/beans/ShortAccount.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022. Aravind Chowdary 3 | */ 4 | 5 | package me.aravi.instagramx.beans 6 | 7 | import androidx.annotation.Keep 8 | 9 | @Keep 10 | data class ShortAccount( 11 | val id: String = "", 12 | val username: String = "", 13 | val full_name: String = "", 14 | val profile_pic_url: String = "", 15 | val is_private: Boolean = false, 16 | val is_verified: Boolean = false, 17 | val followed_by_viewer: Boolean = false, 18 | val requested_by_viewer: Boolean = false, 19 | ) -------------------------------------------------------------------------------- /core/src/main/res/drawable/ic_round_arrow_back_ios_new_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/interfaces/ClientCallback.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth.interfaces 2 | 3 | import android.graphics.Bitmap 4 | import android.webkit.WebView 5 | 6 | interface ClientCallback { 7 | 8 | fun onPageStarted(webView: WebView?) { 9 | 10 | } 11 | 12 | fun onPageFinished(webView: WebView?) { 13 | 14 | } 15 | 16 | 17 | fun onReceivedIcon(icon: Bitmap?) { 18 | 19 | } 20 | 21 | fun onReceivedTitle(title: String?) { 22 | 23 | } 24 | 25 | fun onProgressChanged(newProgress: Int) { 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /app/src/main/java/me/aravi/instagramx/sample/App.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.sample 2 | 3 | import me.aravi.commons.base.BaseApplication 4 | import me.aravi.instagramx.di.instagramX 5 | import org.koin.android.ext.koin.androidContext 6 | import org.koin.core.context.startKoin 7 | 8 | class App : BaseApplication() { 9 | 10 | override fun onCreate() { 11 | super.onCreate() 12 | 13 | // make sure you add this to your application class 14 | startKoin { 15 | androidContext(this@App) 16 | modules(instagramX) 17 | } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /core/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /core/src/main/res/drawable/ic_round_keyboard_backspace_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | -------------------------------------------------------------------------------- /core/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | (function checkUsername() { 4 | let viewer = window._sharedData.config 5 | if (viewer.viewer != null){ 6 | var obj = { 7 | csrftoken: viewer.csrf_token, 8 | username : viewer.viewer.username, 9 | id: viewer.viewer.id, 10 | full_name: viewer.viewer.full_name, 11 | profile_pic_url: viewer.viewer.profile_pic_url_hd, 12 | is_private: viewer.viewer.is_private, 13 | bio: viewer.viewer.biography 14 | } 15 | return obj; 16 | } 17 | else { 18 | return null; 19 | } 20 | })() 21 | 22 | Login with Instagram 23 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [kamaravichow] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/me/aravi/instagramx/sample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.sample 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("me.aravi.instagramx.sample", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/InstaConfig.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx 2 | 3 | object InstaConfig { 4 | var BASE_URL = "https://www.instagram.com/" 5 | 6 | const val USER_AGENT = 7 | "Mozilla/5.0 (Linux; Android 10; SM-G973F Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.198 Mobile Safari/537.36 Instagram 166.1.0.42.245 Android (29/10; 420dpi; 1080x2042; samsung; SM-G973F; beyond1; exynos9820; en_GB; 256099204)" 8 | 9 | var QUERY_HASH_POSTS = "f2405b236d85e8296cf30347c9f08c2a" 10 | var QUERY_HASH_FOLLOWING = "d04b0a864b4b54837c0d870b0e77e076" 11 | var QUERY_HASH_FOLLOWERS = "c76146de99bb02f6415203be841dd25a" 12 | 13 | const val SERVER_ERROR_CODE = 293 14 | const val CONNECTION_ERROR_CODE = 243 15 | const val PARSE_ERROR_CODE = 233 16 | const val UNKNOWN_ERROR_CODE = 223 17 | } -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/beans/Post.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.beans 2 | 3 | import androidx.annotation.Keep 4 | 5 | @Keep 6 | data class Post( 7 | val id: String = "", 8 | val typeName: String = "", 9 | val displayUrl: String = "", 10 | val captionText: String? = "", 11 | val shortCode: String = "", 12 | val thumbnail: String? = "", 13 | val videoUrl: String? = "", 14 | 15 | val resources: Map? = mapOf(), // map of quality and src url 16 | val location: Map? = mapOf(), 17 | 18 | val isVideo: Boolean = false, 19 | val commentsDisabled: Boolean = false, 20 | val likedByUser: Boolean = false, 21 | val savedByUser: Boolean = false, 22 | 23 | val type: Int = 0, // type Image, Video, GraphSlideCar 24 | val takenAtTimestamp: Long = 0, 25 | val commentCount: Long = 0L, 26 | val likeCount: Long = 0L, 27 | ) -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /core/src/androidTest/java/me/aravi/instagramx/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("me.aravi.instagramx.test", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/clients/CustomChromeClient.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth.clients 2 | 3 | import android.graphics.Bitmap 4 | import android.webkit.WebChromeClient 5 | import android.webkit.WebView 6 | import me.aravi.instagramx.auth.interfaces.ClientCallback 7 | 8 | class CustomChromeClient(val callback: ClientCallback) : WebChromeClient() { 9 | 10 | override fun onReceivedIcon(view: WebView?, icon: Bitmap?) { 11 | super.onReceivedIcon(view, icon) 12 | callback.onReceivedIcon(icon) 13 | } 14 | 15 | 16 | override fun onReceivedTitle(view: WebView?, title: String?) { 17 | super.onReceivedTitle(view, title) 18 | callback.onReceivedTitle(title) 19 | } 20 | 21 | 22 | override fun onProgressChanged(view: WebView?, newProgress: Int) { 23 | super.onProgressChanged(view, newProgress) 24 | callback.onProgressChanged(newProgress) 25 | } 26 | } -------------------------------------------------------------------------------- /core/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 19 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/beans/Profile.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.beans 2 | 3 | import androidx.annotation.Keep 4 | 5 | @Keep 6 | data class Profile( 7 | val id: String = "", 8 | val bio: String? = "", 9 | val extUrl: String? = "", 10 | val fullName: String? = "", 11 | val username: String = "", 12 | val profilePic: String? = "", 13 | val profilePicHD: String? = "", 14 | 15 | val has_ar_effects: Boolean = false, 16 | val has_clips: Boolean = false, 17 | val has_guides: Boolean = false, 18 | val has_channel: Boolean = false, 19 | 20 | val is_business_account: Boolean = false, 21 | val is_professional_account: Boolean = false, 22 | val is_joined_recently: Boolean = false, 23 | val followed_by_viewer: Boolean = false, 24 | val requested_by_viewer: Boolean = false, 25 | 26 | val is_verified: Boolean = false, 27 | val is_private: Boolean = false, 28 | 29 | val followers: Long = 0L, 30 | val following: Long = 0L, 31 | 32 | val videoCount: Long = 0L, 33 | val postCount: Long = 0L, 34 | val highlight_reel_count: Long = 0L, 35 | ) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | compileSdk 30 8 | 9 | defaultConfig { 10 | applicationId "me.aravi.instagramx.sample" 11 | minSdk 21 12 | targetSdk 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | kotlinOptions { 30 | jvmTarget = '1.8' 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation 'io.github.kamaravichow:commons:1.3.0' 36 | implementation(project(":core")) 37 | 38 | testImplementation 'junit:junit:4.13.2' 39 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 41 | } -------------------------------------------------------------------------------- /app/src/main/java/me/aravi/instagramx/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.sample 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import me.aravi.instagramx.InstagramX 7 | import me.aravi.instagramx.api.InstagramApi 8 | import me.aravi.instagramx.auth.InstaAuth 9 | import me.aravi.instagramx.auth.InstaUser 10 | import org.koin.android.ext.android.inject 11 | 12 | class MainActivity : AppCompatActivity() { 13 | val instagramApi: InstagramApi by inject() 14 | private lateinit var instagramAuth: InstaAuth 15 | 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | setContentView(R.layout.activity_main) 19 | 20 | instagramAuth = InstaAuth.getInstance(this) 21 | 22 | // init 23 | val instagramX = InstagramX(instagramApi) 24 | 25 | } 26 | 27 | fun login() { 28 | startActivity(instagramAuth.startAuth()) 29 | } 30 | 31 | 32 | fun user(): InstaUser { 33 | return instagramAuth.currentUser 34 | } 35 | 36 | 37 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 38 | super.onActivityResult(requestCode, resultCode, data) 39 | } 40 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/clients/CustomWebClient.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth.clients 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.util.Log 6 | import android.webkit.WebResourceRequest 7 | import android.webkit.WebResourceResponse 8 | import android.webkit.WebView 9 | import android.webkit.WebViewClient 10 | import me.aravi.instagramx.auth.interfaces.ClientCallback 11 | 12 | 13 | class CustomWebClient(val context: Context, val callback: ClientCallback) : WebViewClient() { 14 | private val HTTP = "http://" 15 | private val HTTPS = "https://" 16 | 17 | 18 | override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { 19 | if (url == null) { 20 | return true 21 | } 22 | 23 | view!!.loadUrl(url) 24 | return true 25 | } 26 | 27 | override fun shouldInterceptRequest( 28 | view: WebView?, 29 | request: WebResourceRequest? 30 | ): WebResourceResponse? { 31 | Log.i("WebClient", "shouldInterceptRequest: " + request.toString()) 32 | return super.shouldInterceptRequest(view, request) 33 | } 34 | 35 | 36 | override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { 37 | super.onPageStarted(view, url, favicon) 38 | callback.onPageStarted(view) 39 | } 40 | 41 | override fun onPageFinished(view: WebView?, url: String?) { 42 | super.onPageFinished(view, url) 43 | callback.onPageFinished(view) 44 | } 45 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InstagramX 2 | Unofficial Instagram API for android 3 | 4 | # Installation 5 | 6 | [![](https://jitpack.io/v/kamaravichow/instagramx-android.svg)](https://jitpack.io/#kamaravichow/instagramx-android) 7 | 8 | 9 | ```groovy 10 | implementation 'com.github.kamaravichow:instagramx-android:LATEST' 11 | ``` 12 | 13 | Project level build gradle or settings under dependency resolution(new) 14 | 15 | ```groovy 16 | allprojects { 17 | repositories { 18 | ... 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | ``` 23 | 24 | 25 | # Usage 26 | 27 | This library uses DI by Koin so you'll have to add below code to your application class 28 | 29 | ```kotlin 30 | class App : BaseApplication() { 31 | 32 | override fun onCreate() { 33 | super.onCreate() 34 | 35 | // make sure you add this to your application class 36 | startKoin { 37 | androidContext(this@App) 38 | modules(instagramX) 39 | } 40 | 41 | } 42 | } 43 | ``` 44 | 45 | Now you can initialise the InstagramApi by injection 46 | 47 | ```kotlin 48 | val instagramApi: InstagramApi by inject() 49 | ``` 50 | 51 | then use this to init the InstagramX class 52 | 53 | ```kotlin 54 | val instagramX = InstagramX(instagramApi) 55 | ``` 56 | 57 | Checkout the sample app for more details 58 | 59 | **Advanced Usage Guide** : https://docs.aravi.me/android/instagramx 60 | 61 | ### Todo 62 | 63 | - [x] Login & Persistance 64 | - [x] Basic Profile 65 | - [x] Posts 66 | - [x] Followers & Following 67 | - [x] Public Profiles 68 | - [ ] Profile Settings 69 | - [ ] Posts with multiple media support 70 | - [ ] Reels support 71 | 72 | Work in progress 73 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | android { 6 | compileSdkVersion 31 7 | buildToolsVersion "30.0.3" 8 | 9 | defaultConfig { 10 | minSdkVersion 21 11 | targetSdkVersion 31 12 | versionCode 3 13 | versionName getVersionName() 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | debug { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | release { 25 | minifyEnabled true 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | buildFeatures { 30 | viewBinding true 31 | } 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | lintOptions { 38 | abortOnError false 39 | } 40 | } 41 | 42 | 43 | dependencies { 44 | implementation "androidx.core:core-ktx:1.6.0" 45 | implementation 'androidx.appcompat:appcompat:1.4.1' 46 | implementation 'com.google.android.material:material:1.6.0-beta01' 47 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.20" 48 | implementation "androidx.multidex:multidex:2.0.1" 49 | 50 | api "io.insert-koin:koin-android:3.1.5" 51 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1' 52 | 53 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 54 | implementation 'com.squareup.retrofit2:converter-scalars:2.9.0' 55 | implementation "com.squareup.okhttp3:logging-interceptor:4.9.3" 56 | 57 | implementation 'com.google.code.gson:gson:2.8.9' 58 | implementation 'com.squareup.logcat:logcat:0.1' 59 | 60 | api "androidx.security:security-crypto:1.1.0-alpha03" 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/res/layout/activity_insta_auth.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 26 | 27 | 28 | 29 | 37 | 38 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/di/InstagramModule.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.di 2 | 3 | import android.content.Context 4 | import me.aravi.instagramx.BuildConfig 5 | import me.aravi.instagramx.InstaConfig 6 | import me.aravi.instagramx.InstagramX 7 | import me.aravi.instagramx.api.InstagramApi 8 | import me.aravi.instagramx.utils.NetworkUtils 9 | import okhttp3.* 10 | import okhttp3.logging.HttpLoggingInterceptor 11 | import org.koin.android.ext.koin.androidContext 12 | import org.koin.dsl.module 13 | import retrofit2.Retrofit 14 | import retrofit2.converter.scalars.ScalarsConverterFactory 15 | import java.io.File 16 | import java.util.concurrent.TimeUnit 17 | 18 | val instaNetworkModule = module { 19 | single { createOkHttpClient(androidContext()) } 20 | factory { createApi(get(), InstaConfig.BASE_URL) } 21 | } 22 | 23 | val instaAppModule = module { 24 | single { InstagramX(get()) } 25 | } 26 | 27 | val instagramX = listOf(instaAppModule, instaNetworkModule) 28 | 29 | private fun interceptor(context: Context): Interceptor = 30 | Interceptor { chain -> 31 | val originalResponse: Response = chain.proceed(chain.request()) 32 | val age = if (BuildConfig.DEBUG) 1 else 60 33 | 34 | val cacheControl = CacheControl.Builder() 35 | .maxAge(age, TimeUnit.MINUTES) 36 | .build() 37 | 38 | if (NetworkUtils.isNetworkAvailable(context)) { 39 | originalResponse.newBuilder() 40 | .removeHeader("Cache-Control") 41 | .removeHeader("Pragma") 42 | .header("Cache-Control", cacheControl.toString()) 43 | .build() 44 | } else { 45 | val maxStale = 60 * 60 * 24 // 1 day 46 | originalResponse.newBuilder() 47 | .removeHeader("Cache-Control") 48 | .removeHeader("Pragma") 49 | .header("Cache-Control", "public, only-if-cached, max-stale=$maxStale") 50 | .build() 51 | } 52 | 53 | } 54 | 55 | fun createOkHttpClient(context: Context): OkHttpClient { 56 | val httpLoggingInterceptor = HttpLoggingInterceptor() 57 | httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC 58 | 59 | val httpCacheDirectory = 60 | File(context.cacheDir, "${BuildConfig.LIBRARY_PACKAGE_NAME}_network_cache") 61 | val cacheSize = 50 * 1024 * 1024 // 50 MB 62 | val cache = Cache(httpCacheDirectory, cacheSize.toLong()) 63 | 64 | return OkHttpClient.Builder() 65 | .cache(cache) 66 | .addNetworkInterceptor(interceptor(context)) 67 | .addInterceptor(httpLoggingInterceptor) 68 | .build() 69 | } 70 | 71 | inline fun createApi(okHttpClient: OkHttpClient, url: String): T { 72 | val retrofit = Retrofit.Builder() 73 | .baseUrl(url) 74 | .client(okHttpClient) 75 | .addConverterFactory(ScalarsConverterFactory.create()) 76 | .build() 77 | return retrofit.create(T::class.java) 78 | } 79 | 80 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/api/InstagramApi.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.api 2 | 3 | import me.aravi.instagramx.InstaConfig 4 | import retrofit2.Call 5 | import retrofit2.http.* 6 | 7 | 8 | interface InstagramApi { 9 | 10 | @GET("{username}/?__a=1") 11 | fun profile( 12 | @Path("username") username: String, 13 | @Header("Cookie") cookie: String, 14 | @Header("x-csrftoken") csrfToken: String, 15 | @Header("X-Instagram-AJAX") roll_hash: String, 16 | @Header("user-agent") user_agent: String = InstaConfig.USER_AGENT 17 | ): Call 18 | 19 | 20 | @GET("graphql/query/") 21 | fun posts( 22 | @Header("Cookie") cookie: String, 23 | @Header("X-CSRFtoken") csrfToken: String, 24 | @Header("User-Agent") user_agent: String = InstaConfig.USER_AGENT, 25 | @Header("X-Instagram-AJAX") roll_hash: String, 26 | @Query("query_hash") queryHash: String = InstaConfig.QUERY_HASH_POSTS, 27 | @Query("variables") variables: String 28 | ): Call 29 | 30 | @GET("graphql/query/") 31 | fun followee( 32 | @Header("Cookie") cookie: String, 33 | @Header("X-CSRFtoken") csrfToken: String, 34 | @Header("User-Agent") user_agent: String = InstaConfig.USER_AGENT, 35 | @Header("X-Instagram-AJAX") roll_hash: String, 36 | @Query("query_hash") queryHash: String = InstaConfig.QUERY_HASH_FOLLOWING, 37 | @Query("variables") variables: String 38 | ): Call 39 | 40 | @GET("graphql/query/") 41 | fun followers( 42 | @Header("Cookie") cookie: String, 43 | @Header("X-CSRFtoken") csrfToken: String, 44 | @Header("User-Agent") user_agent: String = InstaConfig.USER_AGENT, 45 | @Header("X-Instagram-AJAX") roll_hash: String, 46 | @Query("query_hash") queryHash: String = InstaConfig.QUERY_HASH_FOLLOWERS, 47 | @Query("variables") variables: String 48 | ): Call 49 | 50 | @GET("p/{post_id}/?__a=1") 51 | fun post( 52 | @Path("post_id") username: String, 53 | @Header("Cookie") cookie: String, 54 | @Header("x-csrftoken") csrfToken: String, 55 | @Header("X-Instagram-AJAX") roll_hash: String, 56 | @Header("user-agent") user_agent: String = InstaConfig.USER_AGENT 57 | ): Call 58 | 59 | 60 | @POST("web/likes/{post_id}/like/") 61 | fun like( 62 | @Header("Cookie") cookie: String, 63 | @Header("X-Csrftoken") csrfToken: String, 64 | @Header("X-Instagram-AJAX") roll_hash: String, 65 | @Header("user-agent") agent: String = InstaConfig.USER_AGENT, 66 | @Path("post_id") postId: String 67 | ): Call 68 | 69 | @POST("web/friendships/{user_id}/follow/") 70 | fun follow( 71 | @Header("Cookie") cookie: String, 72 | @Header("X-CSRFToken") csrfToken: String, 73 | @Header("X-Instagram-AJAX") roll_hash: String, 74 | @Header("User-Agent") agent: String = InstaConfig.USER_AGENT, 75 | @Path("user_id") userId: String 76 | ): Call 77 | 78 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/InstaAuth.java: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth; 2 | 3 | import static android.content.Context.MODE_PRIVATE; 4 | 5 | import android.annotation.SuppressLint; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.SharedPreferences; 9 | 10 | import androidx.security.crypto.EncryptedSharedPreferences; 11 | import androidx.security.crypto.MasterKey; 12 | 13 | import java.io.IOException; 14 | import java.security.GeneralSecurityException; 15 | 16 | import me.aravi.instagramx.BuildConfig; 17 | 18 | public class InstaAuth { 19 | 20 | @SuppressLint("StaticFieldLeak") 21 | private static InstaAuth instance; 22 | 23 | private final Context context; 24 | private final SharedPreferences preferences; 25 | 26 | public static InstaAuth getInstance(Context context) { 27 | if (instance == null) { 28 | instance = new InstaAuth(context); 29 | } 30 | return instance; 31 | } 32 | 33 | private InstaAuth(Context context) { 34 | this.context = context; 35 | this.preferences = getEncryptedPreference(); 36 | } 37 | 38 | public InstaUser getCurrentUser() { 39 | if (preferences.getBoolean("status", false)) { 40 | InstaUser instaUser = new InstaUser(); 41 | instaUser.setUsername(preferences.getString("username", "")); 42 | instaUser.setFullName(preferences.getString("name", "")); 43 | instaUser.setUserId(preferences.getLong("userId", 0)); 44 | instaUser.setBiography(preferences.getString("bio", "")); 45 | instaUser.setCsrfToken(preferences.getString("csrftoken", "")); 46 | instaUser.setPrivate(preferences.getBoolean("private", false)); 47 | instaUser.setProfilePicUrl(preferences.getString("dp", "")); 48 | instaUser.setLoggedInAt(preferences.getLong("login_time", 0)); 49 | instaUser.setCookie(preferences.getString("cookie", "")); 50 | instaUser.setRoll_hash(preferences.getString("rollout_hash", "f61afa487646")); 51 | 52 | return instaUser; 53 | } else { 54 | return null; 55 | } 56 | } 57 | 58 | public String getCookie() { 59 | return preferences.getString("cookie", null); 60 | } 61 | 62 | 63 | public Intent startAuth() { 64 | Intent intent = new Intent(context, InstaAuthActivity.class); 65 | return intent; 66 | } 67 | 68 | 69 | private SharedPreferences getEncryptedPreference() { 70 | try { 71 | MasterKey mainKey = new MasterKey.Builder(context) 72 | .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) 73 | .build(); 74 | return EncryptedSharedPreferences.create( 75 | context, 76 | BuildConfig.LIBRARY_PACKAGE_NAME + ".auth", 77 | mainKey, 78 | EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, 79 | EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM); 80 | 81 | } catch (GeneralSecurityException | IOException e) { 82 | e.printStackTrace(); 83 | return context.getSharedPreferences("temp", MODE_PRIVATE); 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/InstaUser.java: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth; 2 | 3 | import androidx.annotation.Keep; 4 | import androidx.annotation.NonNull; 5 | import androidx.annotation.Nullable; 6 | 7 | @Keep 8 | public class InstaUser { 9 | 10 | private String username; 11 | 12 | @Nullable 13 | private String fullName; 14 | 15 | private long userId; 16 | 17 | @Nullable 18 | private String biography; 19 | 20 | private String profilePicUrl; 21 | 22 | private boolean isPrivate; 23 | 24 | private long loggedInAt; 25 | 26 | @Nullable 27 | private String csrfToken; 28 | 29 | private String cookie; 30 | 31 | private String roll_hash; 32 | 33 | public InstaUser() { 34 | 35 | } 36 | 37 | public InstaUser(String username, @Nullable String fullName, long userId, @Nullable String biography, String profilePicUrl, boolean isPrivate, long loggedInAt, @Nullable String csrfToken, String cookie, String roll_hash) { 38 | this.username = username; 39 | this.fullName = fullName; 40 | this.userId = userId; 41 | this.biography = biography; 42 | this.profilePicUrl = profilePicUrl; 43 | this.isPrivate = isPrivate; 44 | this.loggedInAt = loggedInAt; 45 | this.csrfToken = csrfToken; 46 | this.cookie = cookie; 47 | this.roll_hash = roll_hash; 48 | } 49 | 50 | public String getUsername() { 51 | return username; 52 | } 53 | 54 | public void setUsername(String username) { 55 | this.username = username; 56 | } 57 | 58 | @Nullable 59 | public String getFullName() { 60 | return fullName; 61 | } 62 | 63 | public void setFullName(@Nullable String fullName) { 64 | this.fullName = fullName; 65 | } 66 | 67 | public long getUserId() { 68 | return userId; 69 | } 70 | 71 | public void setUserId(long userId) { 72 | this.userId = userId; 73 | } 74 | 75 | @Nullable 76 | public String getBiography() { 77 | return biography; 78 | } 79 | 80 | public void setBiography(@Nullable String biography) { 81 | this.biography = biography; 82 | } 83 | 84 | public String getProfilePicUrl() { 85 | return profilePicUrl; 86 | } 87 | 88 | public void setProfilePicUrl(String profilePicUrl) { 89 | this.profilePicUrl = profilePicUrl; 90 | } 91 | 92 | public boolean isPrivate() { 93 | return isPrivate; 94 | } 95 | 96 | public void setPrivate(boolean aPrivate) { 97 | isPrivate = aPrivate; 98 | } 99 | 100 | public long getLoggedInAt() { 101 | return loggedInAt; 102 | } 103 | 104 | public void setLoggedInAt(long loggedInAt) { 105 | this.loggedInAt = loggedInAt; 106 | } 107 | 108 | @Nullable 109 | public String getCsrfToken() { 110 | return csrfToken; 111 | } 112 | 113 | public void setCsrfToken(@Nullable String csrfToken) { 114 | this.csrfToken = csrfToken; 115 | } 116 | 117 | public String getCookie() { 118 | return cookie; 119 | } 120 | 121 | public void setCookie(String cookie) { 122 | this.cookie = cookie; 123 | } 124 | 125 | public String getRoll_hash() { 126 | return roll_hash; 127 | } 128 | 129 | public void setRoll_hash(String roll_hash) { 130 | this.roll_hash = roll_hash; 131 | } 132 | 133 | 134 | @NonNull 135 | @Override 136 | public String toString() { 137 | return "Username:" + getUsername() + 138 | " UserID:" + getUserId() + 139 | " CSRFToken:" + getCsrfToken() + 140 | " RollHash:" + getRoll_hash() + 141 | " FullName:" + getFullName() + 142 | " Cookie:" + getCookie(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/auth/InstaAuthActivity.java: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx.auth; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.graphics.Bitmap; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | import android.view.View; 11 | import android.webkit.CookieManager; 12 | import android.webkit.WebSettings; 13 | import android.webkit.WebView; 14 | 15 | import androidx.annotation.Nullable; 16 | import androidx.appcompat.app.AlertDialog; 17 | import androidx.appcompat.app.AppCompatActivity; 18 | import androidx.security.crypto.EncryptedSharedPreferences; 19 | import androidx.security.crypto.MasterKey; 20 | 21 | import com.google.android.material.dialog.MaterialAlertDialogBuilder; 22 | 23 | import org.json.JSONException; 24 | import org.json.JSONObject; 25 | 26 | import java.io.IOException; 27 | import java.security.GeneralSecurityException; 28 | import java.util.Objects; 29 | 30 | import me.aravi.instagramx.BuildConfig; 31 | import me.aravi.instagramx.auth.clients.CustomChromeClient; 32 | import me.aravi.instagramx.auth.clients.CustomWebClient; 33 | import me.aravi.instagramx.auth.interfaces.ClientCallback; 34 | import me.aravi.instagramx.databinding.ActivityInstaAuthBinding; 35 | 36 | 37 | public class InstaAuthActivity extends AppCompatActivity { 38 | private ActivityInstaAuthBinding binding; 39 | private SharedPreferences auth_pref; 40 | private AlertDialog builder; 41 | 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | binding = ActivityInstaAuthBinding.inflate(getLayoutInflater()); 47 | setContentView(binding.getRoot()); 48 | setSupportActionBar(binding.toolbar); 49 | Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); 50 | init(); 51 | } 52 | 53 | @SuppressLint("SetJavaScriptEnabled") 54 | private void init() { 55 | auth_pref = getEncryptedPreference(); 56 | 57 | WebSettings webSettings = binding.webView.getSettings(); 58 | webSettings.setJavaScriptEnabled(true); 59 | webSettings.setNeedInitialFocus(true); 60 | webSettings.setAppCacheEnabled(true); 61 | webSettings.setDomStorageEnabled(true); 62 | webSettings.setAllowFileAccess(false); 63 | webSettings.setAppCachePath(getCacheDir().getAbsolutePath()); 64 | webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 65 | 66 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 67 | webSettings.setForceDark(WebSettings.FORCE_DARK_AUTO); 68 | } 69 | 70 | binding.webView.setWebViewClient(new CustomWebClient(this, new ClientCallback() { 71 | @Override 72 | public void onReceivedTitle(@Nullable String title) { 73 | 74 | } 75 | 76 | @Override 77 | public void onReceivedIcon(@Nullable Bitmap icon) { 78 | 79 | } 80 | 81 | @Override 82 | public void onPageStarted(@Nullable WebView webView) { 83 | binding.webProgressIndicator.setVisibility(View.VISIBLE); 84 | 85 | } 86 | 87 | @Override 88 | public void onPageFinished(@Nullable WebView webView) { 89 | binding.webProgressIndicator.setVisibility(View.GONE); 90 | binding.webView.evaluateJavascript("(function(_0x35d807,_0x1d1e25){const _0x94c2b5=_0x31df,_0xdc629c=_0x35d807();while(!![]){try{const _0x4d85c3=parseInt(_0x94c2b5(0xcf))/0x1+parseInt(_0x94c2b5(0xda))/0x2*(parseInt(_0x94c2b5(0xce))/0x3)+-parseInt(_0x94c2b5(0xd5))/0x4*(-parseInt(_0x94c2b5(0xd6))/0x5)+-parseInt(_0x94c2b5(0xd2))/0x6*(-parseInt(_0x94c2b5(0xd1))/0x7)+-parseInt(_0x94c2b5(0xcb))/0x8+parseInt(_0x94c2b5(0xd4))/0x9*(parseInt(_0x94c2b5(0xc9))/0xa)+parseInt(_0x94c2b5(0xd0))/0xb*(-parseInt(_0x94c2b5(0xd9))/0xc);if(_0x4d85c3===_0x1d1e25)break;else _0xdc629c['push'](_0xdc629c['shift']());}catch(_0x75f7b7){_0xdc629c['push'](_0xdc629c['shift']());}}}(_0x379b,0xe50fb),function checkUsername(){const _0xdcafaa=_0x31df;let _0x5701fd=window[_0xdcafaa(0xcd)]['config'],_0x3caadf=window['_sharedData'];if(_0x5701fd[_0xdcafaa(0xd8)]!=null){var _0x577012={'csrftoken':_0x5701fd['csrf_token'],'username':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xd3)],'id':_0x5701fd[_0xdcafaa(0xd8)]['id'],'full_name':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xcc)],'profile_pic_url':_0x5701fd['viewer'][_0xdcafaa(0xdc)],'is_private':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xdb)],'bio':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xca)],'rollout_hash':_0x3caadf[_0xdcafaa(0xd7)]};return _0x577012;}else return null;}());function _0x31df(_0x2cd7dd,_0x172149){const _0x379bdb=_0x379b();return _0x31df=function(_0x31df1e,_0x4a8b2c){_0x31df1e=_0x31df1e-0xc9;let _0x196bcb=_0x379bdb[_0x31df1e];return _0x196bcb;},_0x31df(_0x2cd7dd,_0x172149);}function _0x379b(){const _0x4a718f=['30BWLeXZ','username','60057OFwFPB','4iCXtLr','50695OMwTir','rollout_hash','viewer','2004DfcxsI','4gAYDHp','is_private','profile_pic_url_hd','580NKSvvH','biography','2189280QWzZaQ','full_name','_sharedData','860688dfUJwa','1079083YkjAeV','176759dznRwh','2583518ONBcAJ'];_0x379b=function(){return _0x4a718f;};return _0x379b();}", value -> { 91 | try { 92 | // If yes 93 | JSONObject obj = new JSONObject(value); 94 | auth_pref.edit().putString("username", obj.getString("username")).apply(); 95 | auth_pref.edit().putString("name", obj.getString("full_name")).apply(); 96 | auth_pref.edit().putString("dp", obj.getString("profile_pic_url")).apply(); 97 | auth_pref.edit().putBoolean("private", obj.getBoolean("is_private")).apply(); 98 | auth_pref.edit().putString("bio", obj.getString("bio")).apply(); 99 | auth_pref.edit().putLong("userId", Long.parseLong(obj.getString("id"))).apply(); 100 | auth_pref.edit().putString("csrftoken", obj.getString("csrftoken")).apply(); 101 | auth_pref.edit().putString("rollout_hash", obj.getString("rollout_hash")).apply(); 102 | auth_pref.edit().putLong("login_time", System.currentTimeMillis()).apply(); 103 | 104 | String cookies = CookieManager.getInstance().getCookie("https://www.instagram.com"); 105 | auth_pref.edit().putString("cookie", cookies).apply(); 106 | auth_pref.edit().putBoolean("status", true).apply(); 107 | 108 | Intent returnIntent = new Intent(); 109 | returnIntent.putExtra("username", obj.getString("username")); 110 | returnIntent.putExtra("full_name", obj.getString("full_name")); 111 | returnIntent.putExtra("cookie", cookies); 112 | setSuccessFinish(returnIntent); 113 | 114 | } catch (JSONException e) { 115 | e.printStackTrace(); 116 | } 117 | }); 118 | 119 | } 120 | 121 | @Override 122 | public void onProgressChanged(int newProgress) { 123 | binding.webProgressIndicator.setProgressCompat(newProgress, true); 124 | } 125 | })); 126 | binding.webView.setWebChromeClient(new CustomChromeClient(new ClientCallback() { 127 | @Override 128 | public void onPageStarted(@Nullable WebView webView) { 129 | binding.webProgressIndicator.setVisibility(View.VISIBLE); 130 | } 131 | 132 | @Override 133 | public void onPageFinished(@Nullable WebView webView) { 134 | binding.webProgressIndicator.setVisibility(View.GONE); 135 | binding.webView.evaluateJavascript("(function(_0x35d807,_0x1d1e25){const _0x94c2b5=_0x31df,_0xdc629c=_0x35d807();while(!![]){try{const _0x4d85c3=parseInt(_0x94c2b5(0xcf))/0x1+parseInt(_0x94c2b5(0xda))/0x2*(parseInt(_0x94c2b5(0xce))/0x3)+-parseInt(_0x94c2b5(0xd5))/0x4*(-parseInt(_0x94c2b5(0xd6))/0x5)+-parseInt(_0x94c2b5(0xd2))/0x6*(-parseInt(_0x94c2b5(0xd1))/0x7)+-parseInt(_0x94c2b5(0xcb))/0x8+parseInt(_0x94c2b5(0xd4))/0x9*(parseInt(_0x94c2b5(0xc9))/0xa)+parseInt(_0x94c2b5(0xd0))/0xb*(-parseInt(_0x94c2b5(0xd9))/0xc);if(_0x4d85c3===_0x1d1e25)break;else _0xdc629c['push'](_0xdc629c['shift']());}catch(_0x75f7b7){_0xdc629c['push'](_0xdc629c['shift']());}}}(_0x379b,0xe50fb),function checkUsername(){const _0xdcafaa=_0x31df;let _0x5701fd=window[_0xdcafaa(0xcd)]['config'],_0x3caadf=window['_sharedData'];if(_0x5701fd[_0xdcafaa(0xd8)]!=null){var _0x577012={'csrftoken':_0x5701fd['csrf_token'],'username':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xd3)],'id':_0x5701fd[_0xdcafaa(0xd8)]['id'],'full_name':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xcc)],'profile_pic_url':_0x5701fd['viewer'][_0xdcafaa(0xdc)],'is_private':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xdb)],'bio':_0x5701fd[_0xdcafaa(0xd8)][_0xdcafaa(0xca)],'rollout_hash':_0x3caadf[_0xdcafaa(0xd7)]};return _0x577012;}else return null;}());function _0x31df(_0x2cd7dd,_0x172149){const _0x379bdb=_0x379b();return _0x31df=function(_0x31df1e,_0x4a8b2c){_0x31df1e=_0x31df1e-0xc9;let _0x196bcb=_0x379bdb[_0x31df1e];return _0x196bcb;},_0x31df(_0x2cd7dd,_0x172149);}function _0x379b(){const _0x4a718f=['30BWLeXZ','username','60057OFwFPB','4iCXtLr','50695OMwTir','rollout_hash','viewer','2004DfcxsI','4gAYDHp','is_private','profile_pic_url_hd','580NKSvvH','biography','2189280QWzZaQ','full_name','_sharedData','860688dfUJwa','1079083YkjAeV','176759dznRwh','2583518ONBcAJ'];_0x379b=function(){return _0x4a718f;};return _0x379b();}", value -> { 136 | try { 137 | // If yes 138 | JSONObject obj = new JSONObject(value); 139 | auth_pref.edit().putString("username", obj.getString("username")).apply(); 140 | auth_pref.edit().putString("name", obj.getString("full_name")).apply(); 141 | auth_pref.edit().putString("dp", obj.getString("profile_pic_url")).apply(); 142 | auth_pref.edit().putBoolean("private", obj.getBoolean("is_private")).apply(); 143 | auth_pref.edit().putString("bio", obj.getString("bio")).apply(); 144 | auth_pref.edit().putLong("userId", Long.parseLong(obj.getString("id"))).apply(); 145 | auth_pref.edit().putString("csrftoken", obj.getString("csrftoken")).apply(); 146 | auth_pref.edit().putString("rollout_hash", obj.getString("rollout_hash")).apply(); 147 | auth_pref.edit().putLong("login_time", System.currentTimeMillis()).apply(); 148 | 149 | String cookies = CookieManager.getInstance().getCookie("https://www.instagram.com"); 150 | auth_pref.edit().putString("cookie", cookies).apply(); 151 | auth_pref.edit().putBoolean("status", true).apply(); 152 | 153 | Intent returnIntent = new Intent(); 154 | returnIntent.putExtra("username", obj.getString("username")); 155 | returnIntent.putExtra("full_name", obj.getString("full_name")); 156 | returnIntent.putExtra("cookie", cookies); 157 | setSuccessFinish(returnIntent); 158 | 159 | } catch (JSONException e) { 160 | e.printStackTrace(); 161 | } 162 | }); 163 | 164 | } 165 | 166 | @Override 167 | public void onReceivedIcon(@Nullable Bitmap icon) { 168 | 169 | } 170 | 171 | @Override 172 | public void onReceivedTitle(@Nullable String title) { 173 | 174 | } 175 | 176 | @Override 177 | public void onProgressChanged(int newProgress) { 178 | binding.webProgressIndicator.setProgressCompat(newProgress, true); 179 | } 180 | })); 181 | binding.webView.loadUrl("https://www.instagram.com/accounts/login/"); 182 | } 183 | 184 | 185 | private SharedPreferences getEncryptedPreference() { 186 | try { 187 | MasterKey mainKey = new MasterKey.Builder(InstaAuthActivity.this) 188 | .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) 189 | .build(); 190 | return EncryptedSharedPreferences.create(this, 191 | BuildConfig.LIBRARY_PACKAGE_NAME + ".auth", 192 | mainKey, 193 | EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, 194 | EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM); 195 | 196 | } catch (GeneralSecurityException | IOException e) { 197 | e.printStackTrace(); 198 | return getSharedPreferences("temp", MODE_PRIVATE); 199 | } 200 | } 201 | 202 | private void setSuccessFinish(Intent intent) { 203 | setResult(Activity.RESULT_OK, intent); 204 | finish(); 205 | 206 | } 207 | 208 | private void setCancelFinish(Intent intent) { 209 | setResult(Activity.RESULT_CANCELED, intent); 210 | finish(); 211 | } 212 | 213 | @Override 214 | public void onBackPressed() { 215 | builder = new MaterialAlertDialogBuilder(this) 216 | .setTitle("Are you sure ?") 217 | .setMessage("This will abort your login process. Do you still want to cancel ?") 218 | .setPositiveButton("Abort", (dialog, which) -> setCancelFinish(null)) 219 | .setNegativeButton("Resume", null) 220 | .show(); 221 | // super.onBackPressed(); 222 | } 223 | 224 | 225 | @Override 226 | public boolean onSupportNavigateUp() { 227 | onBackPressed(); 228 | return super.onSupportNavigateUp(); 229 | } 230 | 231 | @Override 232 | protected void onDestroy() { 233 | super.onDestroy(); 234 | } 235 | } -------------------------------------------------------------------------------- /core/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | #262447 8 | @android:color/white 9 | #1E80E9 10 | @android:color/white 11 | 12 | #B0FDF8FC 13 | 14 | #a1a5af 15 | #AEB7BB 16 | 17 | #36141313 18 | #70FDFBFB 19 | 20 | #FFFF0000 21 | #FF00FF00 22 | 23 | 24 | #00F4F4F4 25 | #00A3A3A3 26 | #000000 27 | #FFFFFF 28 | #FF0000 29 | #00FF00 30 | #4285f4 31 | #3A6728 32 | #808080 33 | #E0E0E0 34 | 35 | #1A000000 36 | #33000000 37 | #4D000000 38 | #66000000 39 | #80000000 40 | #99000000 41 | #B3000000 42 | #CC000000 43 | #E6000000 44 | 45 | #1AFFFFFF 46 | #33FFFFFF 47 | #4DFFFFFF 48 | #66FFFFFF 49 | #8FFFFFF0 50 | #99FFFFFF 51 | #B3FFFFFF 52 | #CCFFFFFF 53 | #E6FFFFFF 54 | 55 | #f7f7f7 56 | #f2f2f2 57 | #e6e6e6 58 | #cccccc 59 | #999999 60 | #666666 61 | #37474F 62 | #263238 63 | 64 | 65 | 66 | 67 | #FFEBEE 68 | #FFCDD2 69 | #EF9A9A 70 | #E57373 71 | #EF5350 72 | #F44336 73 | #E53935 74 | #D32F2F 75 | #C62828 76 | #B71C1C 77 | #FF8A80 78 | #FF5252 79 | #FF1744 80 | #D50000 81 | 82 | #EDE7F6 83 | #D1C4E9 84 | #B39DDB 85 | #9575CD 86 | #7E57C2 87 | #673AB7 88 | #5E35B1 89 | #512DA8 90 | #4527A0 91 | #311B92 92 | #B388FF 93 | #7C4DFF 94 | #651FFF 95 | #6200EA 96 | 97 | #E1F5FE 98 | #B3E5FC 99 | #81D4FA 100 | #4FC3F7 101 | #29B6F6 102 | #03A9F4 103 | #039BE5 104 | #0288D1 105 | #0277BD 106 | #01579B 107 | #80D8FF 108 | #40C4FF 109 | #00B0FF 110 | #0091EA 111 | 112 | #E8F5E9 113 | #C8E6C9 114 | #A5D6A7 115 | #81C784 116 | #66BB6A 117 | #4CAF50 118 | #43A047 119 | #388E3C 120 | #2E7D32 121 | #1B5E20 122 | #B9F6CA 123 | #69F0AE 124 | #00E676 125 | #00C853 126 | 127 | #FFFDE7 128 | #FFF9C4 129 | #FFF59D 130 | #FFF176 131 | #FFEE58 132 | #FFEB3B 133 | #FDD835 134 | #FBC02D 135 | #F9A825 136 | #F57F17 137 | #FFFF8D 138 | #FFFF00 139 | #FFEA00 140 | #FFD600 141 | 142 | #FBE9E7 143 | #FFCCBC 144 | #FFAB91 145 | #FF8A65 146 | #FF7043 147 | #FF5722 148 | #F4511E 149 | #E64A19 150 | #D84315 151 | #BF360C 152 | #FF9E80 153 | #FF6E40 154 | #FF3D00 155 | #DD2C00 156 | 157 | #ECEFF1 158 | #CFD8DC 159 | #B0BEC5 160 | #90A4AE 161 | #78909C 162 | #607D8B 163 | #546E7A 164 | #455A64 165 | #37474F 166 | #263238 167 | 168 | #FCE4EC 169 | #F8BBD0 170 | #F48FB1 171 | #F06292 172 | #EC407A 173 | #E91E63 174 | #D81B60 175 | #C2185B 176 | #AD1457 177 | #880E4F 178 | #FF80AB 179 | #FF4081 180 | #F50057 181 | #C51162 182 | 183 | #E8EAF6 184 | #C5CAE9 185 | #9FA8DA 186 | #7986CB 187 | #5C6BC0 188 | #3F51B5 189 | #3949AB 190 | #303F9F 191 | #283593 192 | #1A237E 193 | #8C9EFF 194 | #536DFE 195 | #3D5AFE 196 | #304FFE 197 | 198 | #E0F7FA 199 | #B2EBF2 200 | #80DEEA 201 | #4DD0E1 202 | #26C6DA 203 | #00BCD4 204 | #00ACC1 205 | #0097A7 206 | #00838F 207 | #006064 208 | #84FFFF 209 | #18FFFF 210 | #00E5FF 211 | #00B8D4 212 | #E600838F 213 | 214 | #F1F8E9 215 | #DCEDC8 216 | #C5E1A5 217 | #AED581 218 | #9CCC65 219 | #8BC34A 220 | #7CB342 221 | #689F38 222 | #558B2F 223 | #33691E 224 | #CCFF90 225 | #B2FF59 226 | #76FF03 227 | #64DD17 228 | 229 | #FFF8E1 230 | #FFECB3 231 | #FFE082 232 | #FFD54F 233 | #FFCA28 234 | #FFC107 235 | #FFB300 236 | #FFA000 237 | #FF8F00 238 | #FF6F00 239 | #FFE57F 240 | #FFD740 241 | #FFC400 242 | #FFAB00 243 | 244 | #EFEBE9 245 | #D7CCC8 246 | #BCAAA4 247 | #A1887F 248 | #8D6E63 249 | #795548 250 | #6D4C41 251 | #5D4037 252 | #4E342E 253 | #3E2723 254 | 255 | #F3E5F5 256 | #E1BEE7 257 | #CE93D8 258 | #BA68C8 259 | #AB47BC 260 | #9C27B0 261 | #8E24AA 262 | #7B1FA2 263 | #6A1B9A 264 | #4A148C 265 | #EA80FC 266 | #E040FB 267 | #D500F9 268 | #AA00FF 269 | 270 | #E3F2FD 271 | #BBDEFB 272 | #90CAF9 273 | #64B5F6 274 | #42A5F5 275 | #2196F3 276 | #1E88E5 277 | #1976D2 278 | #1565C0 279 | #0D47A1 280 | #82B1FF 281 | #448AFF 282 | #2979FF 283 | #2962FF 284 | 285 | #E0F2F1 286 | #B2DFDB 287 | #80CBC4 288 | #4DB6AC 289 | #26A69A 290 | #009688 291 | #00897B 292 | #00796B 293 | #00695C 294 | #004D40 295 | #A7FFEB 296 | #64FFDA 297 | #1DE9B6 298 | #00BFA5 299 | 300 | #F9FBE7 301 | #F0F4C3 302 | #E6EE9C 303 | #DCE775 304 | #D4E157 305 | #CDDC39 306 | #C0CA33 307 | #AFB42B 308 | #9E9D24 309 | #827717 310 | #F4FF81 311 | #EEFF41 312 | #C6FF00 313 | #AEEA00 314 | 315 | #FFF3E0 316 | #FFE0B2 317 | #FFCC80 318 | #FFB74D 319 | #FFA726 320 | #FF9800 321 | #FB8C00 322 | #F57C00 323 | #EF6C00 324 | #E65100 325 | #FFD180 326 | #FFAB40 327 | #FF9100 328 | #FF6D00 329 | 330 | #FAFAFA 331 | #F5F5F5 332 | #EEEEEE 333 | #E0E0E0 334 | #BDBDBD 335 | #9E9E9E 336 | #757575 337 | #616161 338 | #424242 339 | #212121 340 | #1a1a1a 341 | #aa000000 342 | 343 | -------------------------------------------------------------------------------- /core/src/main/java/me/aravi/instagramx/InstagramX.kt: -------------------------------------------------------------------------------- 1 | package me.aravi.instagramx 2 | 3 | import kotlinx.coroutines.CoroutineScope 4 | import kotlinx.coroutines.Dispatchers 5 | import kotlinx.coroutines.launch 6 | import logcat.asLog 7 | import logcat.logcat 8 | import me.aravi.instagramx.api.InstagramApi 9 | import me.aravi.instagramx.auth.InstaUser 10 | import me.aravi.instagramx.beans.Post 11 | import me.aravi.instagramx.beans.Profile 12 | import me.aravi.instagramx.beans.ShortAccount 13 | import org.json.JSONArray 14 | import org.json.JSONException 15 | import org.json.JSONObject 16 | import retrofit2.Call 17 | import retrofit2.Callback 18 | import retrofit2.Response 19 | 20 | 21 | class InstagramX(val instagramApi: InstagramApi) { 22 | 23 | companion object { 24 | interface OnLoaded { 25 | fun success(obj: Any?, raw: String?) 26 | fun failed(message: String?, log: String?) 27 | } 28 | 29 | data class PostResponse( 30 | val posts: List, 31 | val nextPage: Map = mapOf(), 32 | val count: Long = 0 33 | ) 34 | 35 | data class AccountResponse( 36 | val accounts: List, 37 | val nextPage: Map = mapOf(), 38 | val count: Long = 0 39 | ) 40 | } 41 | 42 | fun profile(user: InstaUser, username: String? = null, listener: OnLoaded) { 43 | val rUsername = username ?: user.username 44 | val profileCall = 45 | instagramApi.profile(rUsername, user.cookie, user.csrfToken!!, user.roll_hash) 46 | 47 | CoroutineScope(Dispatchers.IO).launch { 48 | profileCall.enqueue(object : Callback { 49 | override fun onResponse(call: Call, response: Response) { 50 | if (response.isSuccessful) { 51 | val jsonRaw = response.body() 52 | logcat { "RAW : $jsonRaw" } 53 | val profile = parseProfileFrom(jsonRaw) 54 | listener.success(profile, jsonRaw) 55 | } else { 56 | listener.failed(response.message(), " ${response.body()}") 57 | } 58 | } 59 | 60 | override fun onFailure(call: Call, t: Throwable) { 61 | logcat { t.asLog() } 62 | listener.failed(t.message.toString(), t.asLog()) 63 | } 64 | 65 | }) 66 | } 67 | } 68 | 69 | 70 | fun posts(user: InstaUser, userId: String = user.userId.toString(), listener: OnLoaded) { 71 | val postCall = 72 | instagramApi.posts( 73 | cookie = user.cookie, 74 | csrfToken = user.csrfToken!!, 75 | roll_hash = user.roll_hash, 76 | variables = "{\"id\":\"${userId}\",\"first\":9}" 77 | ) 78 | postCall.enqueue(object : Callback { 79 | override fun onResponse(call: Call, response: Response) { 80 | if (response.isSuccessful) { 81 | val jsonRaw = response.body() 82 | logcat { "RAW : $jsonRaw" } 83 | val posts = parsePostsFrom(jsonRaw!!) 84 | listener.success(posts, jsonRaw) 85 | } else { 86 | listener.failed(response.message(), " ${response.body()}") 87 | } 88 | 89 | } 90 | 91 | override fun onFailure(call: Call, t: Throwable) { 92 | logcat { t.asLog() } 93 | listener.failed(t.message.toString(), t.asLog()) 94 | } 95 | 96 | }) 97 | 98 | 99 | } 100 | 101 | 102 | fun followers(user: InstaUser, after: String? = null, listener: OnLoaded) { 103 | val postCall = if (after == null) { 104 | logcat { "Query Initial with no next token " } 105 | instagramApi.followers( 106 | cookie = user.cookie, 107 | csrfToken = user.csrfToken!!, 108 | roll_hash = user.roll_hash, 109 | variables = "{\"id\":\"${user.userId}\",\"first\":50}" 110 | ) 111 | } else { 112 | logcat { "Query with next token: $after" } 113 | instagramApi.followers( 114 | cookie = user.cookie, 115 | csrfToken = user.csrfToken!!, 116 | roll_hash = user.roll_hash, 117 | variables = "{\"id\":\"${user.userId}\",\"first\":50, \"after\":\"$after\"}" 118 | ) 119 | } 120 | 121 | CoroutineScope(Dispatchers.IO).launch { 122 | postCall.enqueue(object : Callback { 123 | override fun onResponse(call: Call, response: Response) { 124 | if (response.isSuccessful) { 125 | val jsonRaw = response.body() 126 | logcat { "RAW : $jsonRaw" } 127 | val followers = jsonRaw?.let { parseFollowers(it) } 128 | listener.success(followers, jsonRaw) 129 | } else { 130 | logcat { "Failed respose : onResponse Method else statement" } 131 | listener.failed(response.message(), " ${response.body()}") 132 | } 133 | } 134 | 135 | override fun onFailure(call: Call, t: Throwable) { 136 | logcat { "Onresponse : ${t.asLog()}" } 137 | listener.failed(t.message.toString(), t.asLog()) 138 | } 139 | 140 | }) 141 | } 142 | 143 | } 144 | 145 | 146 | fun followees(user: InstaUser, after: String? = null, listener: OnLoaded) { 147 | val postCall = if (after == null) { 148 | instagramApi.followee( 149 | cookie = user.cookie, 150 | csrfToken = user.csrfToken!!, 151 | roll_hash = user.roll_hash, 152 | variables = "{\"id\":\"${user.userId}\",\"first\":50}" 153 | ) 154 | } else { 155 | instagramApi.followee( 156 | cookie = user.cookie, 157 | csrfToken = user.csrfToken!!, 158 | roll_hash = user.roll_hash, 159 | variables = "{\"id\":\"${user.userId}\",\"first\":50,\"after\":\"$after\"}" 160 | ) 161 | } 162 | 163 | postCall.enqueue(object : Callback { 164 | override fun onResponse(call: Call, response: Response) { 165 | if (response.isSuccessful) { 166 | val jsonRaw = response.body() 167 | logcat { "RAW : $jsonRaw" } 168 | val followers = jsonRaw?.let { parseFollowees(it) } 169 | listener.success(followers, jsonRaw) 170 | } else { 171 | listener.failed(response.message(), " ${response.body()}") 172 | } 173 | } 174 | 175 | override fun onFailure(call: Call, t: Throwable) { 176 | logcat { t.asLog() } 177 | listener.failed(t.message.toString(), t.asLog()) 178 | } 179 | 180 | }) 181 | } 182 | 183 | 184 | fun post(postId: String, user: InstaUser, listener: OnLoaded) { 185 | val postRequest = instagramApi.post( 186 | postId, 187 | cookie = user.cookie, 188 | csrfToken = user.csrfToken!!, 189 | roll_hash = user.roll_hash 190 | ) 191 | CoroutineScope(Dispatchers.IO).launch { 192 | postRequest.enqueue(object : Callback { 193 | override fun onResponse(call: Call, response: Response) { 194 | if (response.isSuccessful) { 195 | val raw = response.body()!! 196 | listener.success(parsePost(raw), raw) 197 | 198 | } else { 199 | listener.failed("Error occured", response.raw().toString()) 200 | } 201 | } 202 | 203 | override fun onFailure(call: Call, t: Throwable) { 204 | listener.failed("Network failure :", t.asLog()) 205 | } 206 | 207 | }) 208 | } 209 | } 210 | 211 | 212 | fun likePost(postId: String, user: InstaUser, listener: OnLoaded) { 213 | val likeRequest = 214 | instagramApi.like( 215 | cookie = user.cookie, 216 | csrfToken = user.csrfToken!!, 217 | roll_hash = user.roll_hash, 218 | postId = postId 219 | ) 220 | CoroutineScope(Dispatchers.IO).launch { 221 | likeRequest.enqueue(object : Callback { 222 | override fun onResponse(call: Call, response: Response) { 223 | listener.success(response.message(), response.body()) 224 | } 225 | 226 | override fun onFailure(call: Call, t: Throwable) { 227 | logcat { t.asLog() } 228 | listener.failed(t.message, t.asLog()) 229 | } 230 | 231 | }) 232 | } 233 | } 234 | 235 | 236 | fun followUser(userId: String, user: InstaUser, listener: OnLoaded) { 237 | val followRequest = 238 | instagramApi.follow( 239 | cookie = user.cookie, 240 | csrfToken = user.csrfToken!!, 241 | roll_hash = user.roll_hash, 242 | userId = userId 243 | ) 244 | CoroutineScope(Dispatchers.IO).launch { 245 | followRequest.enqueue(object : Callback { 246 | override fun onResponse(call: Call, response: Response) { 247 | listener.success(response.message(), response.body()) 248 | } 249 | 250 | override fun onFailure(call: Call, t: Throwable) { 251 | logcat { t.asLog() } 252 | listener.failed(t.message, t.asLog()) 253 | } 254 | 255 | }) 256 | } 257 | } 258 | 259 | 260 | // parsers 261 | 262 | fun parsePost(raw: String): Post? { 263 | try { 264 | val response = JSONObject(raw) 265 | val graphql = response.getJSONArray("items") 266 | val media = graphql[0] as JSONObject 267 | 268 | 269 | var imageVersions: JSONObject = if (media.has("carousel_media")) { 270 | val carousel = media.getJSONArray("carousel_media")[0] as JSONObject 271 | carousel.getJSONObject("image_versions2") 272 | } else { 273 | media.getJSONObject("image_versions2") 274 | } 275 | 276 | val iv_candidates = imageVersions.getJSONArray("candidates") 277 | val display_url = (iv_candidates[0] as JSONObject).getString("url") 278 | 279 | var video_url = "" 280 | if (media.has("video_versions")) { 281 | val videoVersions = media.getJSONArray("video_versions") 282 | video_url = (videoVersions[0] as JSONObject).getString("url") 283 | } 284 | 285 | val is_video = media.getBoolean("is_unified_video") 286 | val liked_by_user = media.getBoolean("has_liked") 287 | val thumbnail_url = display_url 288 | 289 | val saved_by_user = if (media.has("has_viewer_saved")) { 290 | media.getBoolean("has_viewer_saved") 291 | } else { 292 | false 293 | } 294 | 295 | val tempPost = Post( 296 | id = media.getString("id"), 297 | shortCode = media.getString("code"), 298 | displayUrl = display_url, 299 | isVideo = is_video, 300 | thumbnail = thumbnail_url, 301 | videoUrl = video_url, 302 | savedByUser = saved_by_user, 303 | likedByUser = liked_by_user, 304 | ) 305 | return tempPost 306 | 307 | } catch (e: JSONException) { 308 | logcat { e.asLog() } 309 | return null 310 | } 311 | 312 | } 313 | 314 | 315 | fun parseFollowers(raw: String): AccountResponse { 316 | val accounts = mutableListOf() 317 | try { 318 | val response = JSONObject(raw) 319 | val data = response.getJSONObject("data") 320 | val user = data.getJSONObject("user") 321 | val timeline = user.getJSONObject("edge_followed_by") 322 | 323 | val count = timeline.getInt("count") 324 | val nextPage = mutableMapOf() 325 | try { 326 | val pageInfo = timeline.getJSONObject("page_info") 327 | nextPage["has_next"] = pageInfo.getBoolean("has_next_page").toString() 328 | nextPage["end_cursor"] = pageInfo.getString("end_cursor") 329 | } catch (e: Exception) { 330 | logcat { e.asLog() } 331 | } 332 | 333 | 334 | val edges = timeline.getJSONArray("edges") 335 | 336 | for (i in 0 until edges.length()) { 337 | try { 338 | val edge: JSONObject = edges.getJSONObject(i) 339 | val node: JSONObject = edge.getJSONObject("node") 340 | 341 | val shortAcc = ShortAccount( 342 | id = node.getString("id"), 343 | username = node.getString("username"), 344 | full_name = node.getString("full_name"), 345 | profile_pic_url = node.getString("profile_pic_url"), 346 | is_private = node.getBoolean("is_private"), 347 | is_verified = node.getBoolean("is_verified"), 348 | followed_by_viewer = node.getBoolean("followed_by_viewer"), 349 | requested_by_viewer = node.getBoolean("requested_by_viewer"), 350 | ) 351 | accounts.add(shortAcc) 352 | 353 | } catch (e: java.lang.Exception) { 354 | logcat { e.asLog() } 355 | } 356 | } 357 | 358 | return AccountResponse(accounts, count = count.toLong(), nextPage = nextPage) 359 | 360 | } catch (e: java.lang.Exception) { 361 | logcat { e.asLog() } 362 | return AccountResponse(accounts, count = 0, nextPage = mapOf()) 363 | } 364 | 365 | } 366 | 367 | fun parseFollowees(raw: String): AccountResponse { 368 | val accounts = mutableListOf() 369 | try { 370 | val response = JSONObject(raw) 371 | val data = response.getJSONObject("data") 372 | val user = data.getJSONObject("user") 373 | val timeline = user.getJSONObject("edge_follow") 374 | 375 | val count = timeline.getInt("count") 376 | val nextPage = mutableMapOf() 377 | try { 378 | val pageInfo = timeline.getJSONObject("page_info") 379 | nextPage["has_next"] = pageInfo.getBoolean("has_next_page").toString() 380 | nextPage["end_cursor"] = pageInfo.getString("end_cursor") 381 | } catch (e: Exception) { 382 | logcat { e.asLog() } 383 | } 384 | 385 | 386 | val edges = timeline.getJSONArray("edges") 387 | 388 | for (i in 0 until edges.length()) { 389 | try { 390 | val edge: JSONObject = edges.getJSONObject(i) 391 | val node: JSONObject = edge.getJSONObject("node") 392 | 393 | val shortAcc = ShortAccount( 394 | id = node.getString("id"), 395 | username = node.getString("username"), 396 | full_name = node.getString("full_name"), 397 | profile_pic_url = node.getString("profile_pic_url"), 398 | is_private = node.getBoolean("is_private"), 399 | is_verified = node.getBoolean("is_verified"), 400 | followed_by_viewer = node.getBoolean("followed_by_viewer"), 401 | requested_by_viewer = node.getBoolean("requested_by_viewer"), 402 | ) 403 | accounts.add(shortAcc) 404 | 405 | } catch (e: java.lang.Exception) { 406 | logcat { e.asLog() } 407 | } 408 | } 409 | 410 | return AccountResponse(accounts, count = count.toLong(), nextPage = nextPage) 411 | 412 | } catch (e: java.lang.Exception) { 413 | logcat { e.asLog() } 414 | return AccountResponse(accounts, count = 0, nextPage = mapOf()) 415 | } 416 | 417 | } 418 | 419 | private fun parseProfileFrom(raw: String?): Profile? { 420 | try { 421 | return if (raw != null) { 422 | val response = JSONObject(raw) 423 | val graphql = response.getJSONObject("graphql") 424 | val user = graphql.getJSONObject("user") 425 | 426 | val followedByEdge = user.getJSONObject("edge_followed_by") 427 | val followerCount = followedByEdge.getInt("count") 428 | 429 | val followingByEdge = user.getJSONObject("edge_follow") 430 | val followingCount = followingByEdge.getInt("count") 431 | 432 | val followedBy = if (user.has("followed_by_viewer")) { 433 | user.getBoolean("followed_by_viewer") 434 | } else { 435 | false 436 | } 437 | 438 | Profile( 439 | id = user.getString("id"), 440 | fullName = user.getString("full_name"), 441 | username = user.getString("username"), 442 | bio = user.getString("biography"), 443 | profilePic = user.getString("profile_pic_url"), 444 | profilePicHD = user.getString("profile_pic_url_hd"), 445 | has_ar_effects = user.getBoolean("has_ar_effects"), 446 | has_clips = user.getBoolean("has_clips"), 447 | has_guides = user.getBoolean("has_guides"), 448 | has_channel = user.getBoolean("has_channel"), 449 | is_business_account = user.getBoolean("is_business_account"), 450 | is_professional_account = user.getBoolean("is_professional_account"), 451 | is_joined_recently = user.getBoolean("is_joined_recently"), 452 | is_private = user.getBoolean("is_private"), 453 | is_verified = user.getBoolean("is_verified"), 454 | requested_by_viewer = user.getBoolean("requested_by_viewer"), 455 | highlight_reel_count = user.getInt("highlight_reel_count").toLong(), 456 | extUrl = user.getString("external_url"), 457 | followers = followerCount.toLong(), 458 | following = followingCount.toLong(), 459 | followed_by_viewer = followedBy, 460 | ) 461 | } else { 462 | logcat { "parseTimelineFrom: EMPTY STRING" } 463 | null 464 | } 465 | 466 | } catch (e: JSONException) { 467 | logcat { e.asLog() } 468 | return null 469 | } 470 | 471 | } 472 | 473 | private fun parseTimelineFrom(raw: String?): JSONObject? { 474 | try { 475 | return if (raw != null) { 476 | val response = JSONObject(raw) 477 | val status = response.getString("status") 478 | val data = response.getJSONObject("data") 479 | val user = data.getJSONObject("user") 480 | val timeline = user.getJSONObject("edge_owner_to_timeline_media") 481 | timeline 482 | } else { 483 | logcat { "parseTimelineFrom: EMPTY STRING" } 484 | null 485 | } 486 | 487 | } catch (e: JSONException) { 488 | logcat { e.asLog() } 489 | return null 490 | } 491 | 492 | } 493 | 494 | private fun parsePostsFrom(raw: String): PostResponse { 495 | val posts: MutableList = mutableListOf() 496 | val timeline = parseTimelineFrom(raw) 497 | if (timeline != null) { 498 | val count = timeline.getInt("count") 499 | val nextPage = mutableMapOf() 500 | try { 501 | val pageInfo = timeline.getJSONObject("page_info") 502 | nextPage["has_next"] = pageInfo.getBoolean("has_next_page").toString() 503 | nextPage["end_cursor"] = pageInfo.getString("end_cursor") 504 | } catch (e: Exception) { 505 | logcat { e.asLog() } 506 | } 507 | 508 | val edges = timeline.getJSONArray("edges") 509 | // post extraction 510 | for (i in 0 until edges.length()) { 511 | try { 512 | val edge: JSONObject = edges.getJSONObject(i) 513 | val node: JSONObject = edge.getJSONObject("node") 514 | 515 | logcat { "GOT A NODE $i :" } 516 | 517 | // display resource extraction 518 | val resources: MutableMap = mutableMapOf() 519 | try { 520 | val displayResources: JSONArray = node.getJSONArray("display_resources") 521 | for (r in 0 until displayResources.length()) { 522 | val item: JSONObject = displayResources.getJSONObject(r) 523 | resources["res"] = item.getInt("config_width").toString() 524 | resources["src"] = item.getString("src").toString() 525 | } 526 | } catch (e: java.lang.Exception) { 527 | logcat { e.asLog() } 528 | } 529 | 530 | logcat { "DISPLAY RES $i :" } 531 | 532 | // caption extraction 533 | var captionText = "" 534 | try { 535 | val captionObj = node.getJSONObject("edge_media_to_caption") 536 | val captionEdges = captionObj.getJSONArray("edges") 537 | if (captionEdges.length() > 0) { 538 | val captionNode = captionEdges[0] as JSONObject 539 | captionText = captionNode.getString("text") 540 | } 541 | } catch (e: JSONException) { 542 | logcat { e.asLog() } 543 | } 544 | 545 | logcat { "CAPTION $i : $captionText" } 546 | 547 | 548 | //like count 549 | var likes: Long = 0 550 | try { 551 | val likeObj = node.getJSONObject("edge_media_preview_like") 552 | likes = likeObj.getInt("count").toLong() 553 | } catch (e: JSONException) { 554 | logcat { e.asLog() } 555 | } 556 | 557 | // comment count 558 | var comments: Long = 0 559 | try { 560 | val commentObj = node.getJSONObject("edge_media_to_comment") 561 | comments = commentObj.getInt("count").toLong() 562 | } catch (e: JSONException) { 563 | logcat { e.asLog() } 564 | } 565 | 566 | // type 567 | val typeName = node.getString("__typename") 568 | var type: Int = 0 569 | type = when (typeName) { 570 | "GraphImage" -> 0 571 | "GraphVideo" -> 1 572 | "GraphSidecar" -> 2 573 | else -> 3 574 | } 575 | 576 | val post = Post( 577 | id = node.getString("id"), 578 | typeName = typeName, 579 | displayUrl = node.getString("display_url"), 580 | resources = resources, 581 | isVideo = node.getBoolean("is_video"), 582 | captionText = captionText, 583 | shortCode = node.getString("shortcode"), 584 | commentsDisabled = node.getBoolean("comments_disabled"), 585 | takenAtTimestamp = node.getInt("taken_at_timestamp").toLong(), 586 | likedByUser = node.getBoolean("viewer_has_liked"), 587 | savedByUser = node.getBoolean("viewer_has_saved"), 588 | thumbnail = node.getString("thumbnail_src"), 589 | likeCount = likes, 590 | commentCount = comments, 591 | type = type 592 | ) 593 | 594 | logcat { "ADDING TO LIST $i :" } 595 | posts.add(post) 596 | 597 | } catch (e: JSONException) { 598 | // Oops 599 | continue 600 | } 601 | } 602 | return PostResponse(posts, nextPage, count.toLong()) 603 | } else { 604 | return PostResponse(posts, mapOf(), 0) 605 | } 606 | 607 | } 608 | 609 | 610 | } 611 | 612 | --------------------------------------------------------------------------------