This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 523571b
Showing
36 changed files
with
1,380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Nikola Jakšić | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# InstagramAuth | ||
|
||
An Android library that makes it easy to authenticate your app users with Instagram. | ||
|
||
## Download | ||
|
||
In your project's top-level `build.gradle` file, ensure that JitPack's Maven repository is included: | ||
|
||
```groovy | ||
allprojects { | ||
repositories { | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
|
||
Then, in your app-level `build.gradle` file, declare `InstagramAuth` as a dependency: | ||
|
||
```groovy | ||
dependencies { | ||
implementation 'com.github.nikolajakshic:instagramauth:1.0.0' | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Add `CLIENT_ID` and `REDIRECT_URI` to your `AndroidManifest.xml` file: | ||
|
||
```xml | ||
. . . | ||
|
||
<meta-data | ||
android:name="com.nikola.jakshic.instagramauth.ClientId" | ||
android:value="YOUR_CLIENT_ID"/> | ||
|
||
<meta-data | ||
android:name="com.nikola.jakshic.instagramauth.RedirectUri" | ||
android:value="YOUR_REDIRECT_URI"/> | ||
</application> | ||
</manifest> | ||
``` | ||
|
||
Initialize the library by calling `InstagramAuth.initialize()` from `onCreate` in `Application` or `Activity`/`Fragment`: | ||
|
||
```java | ||
public class MyApp extends Application { | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
InstagramAuth.initialize(this); | ||
} | ||
} | ||
``` | ||
|
||
Call `AuthManager.getInstance().login()` to launch an `Activity` that will, using `WebView`, prompt the User | ||
to log in with Instagram: | ||
|
||
```java | ||
AuthManager.getInstance().login(this, new AuthManager.LoginCallback() { | ||
@Override | ||
public void onSuccess() { | ||
// User successfully logged in, get him to the Home screen or something... | ||
} | ||
|
||
@Override | ||
public void onError(InstagramAuthException e) { | ||
if (e instanceof InstagramAuthAccessDeniedException) { | ||
// User denied access, do something... | ||
} | ||
|
||
if (e instanceof InstagramAuthNetworkOperationException) { | ||
// Network problem, do something... | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
Pass the `Activity`'s result back to the `AuthManager`: | ||
|
||
```java | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
AuthManager.getInstance().onActivityResult(requestCode, resultCode, data); | ||
} | ||
``` | ||
|
||
Use the `AuthManager.getInstance().getUserInfoAsync()` (for synchronous execution, use `getUserInfo()`) method to request basic profile information for the currently signed in User: | ||
|
||
```java | ||
AuthManager.getInstance().getUserInfoAsync(new AuthManager.Callback<UserInfo>() { | ||
@Override | ||
public void onSuccess(UserInfo userInfo) { | ||
String id = userInfo.getId(); | ||
String userName = userInfo.getUserName(); | ||
String fullName = userInfo.getFullName(); | ||
String photoUrl = userInfo.getPhotoUrl(); | ||
|
||
. . . | ||
} | ||
|
||
@Override | ||
public void onError(InstagramAuthException e) { | ||
if (e instanceof InstagramAuthTokenException) { | ||
// Instagram expires the token after some period of time, | ||
// so we need to re-authenticate the User. When this happens, | ||
// library is automatically logging User out, i.e. the old token is removed | ||
// and AuthManager.getInstance().isLoggedIn() returns false. | ||
// | ||
// Prompt the User to log in again. | ||
} | ||
|
||
if (e instanceof InstagramAuthNetworkOperationException) { | ||
// Network problem, do something... | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
Optionally, customize library's `Activity` appearance by overriding the `InstagramAuthTheme` style in your `styles.xml` file: | ||
|
||
```xml | ||
. . . | ||
|
||
<style name="InstagramAuthTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- set toolbar color --> | ||
<item name="colorPrimary">#f44336</item> | ||
<!-- set status bar color--> | ||
<item name="colorPrimaryDark">#d32f2f</item> | ||
<!-- set title --> | ||
<item name="instagram_auth_title">Login with Instagram</item> | ||
</style> | ||
</resources> | ||
``` | ||
|
||
## FAQ | ||
|
||
Q: I get the error message `Implicit authentication is disabled`. What should I do? | ||
A: https://www.instagram.com/developer/clients/manage/ -> Manage -> Security -> Uncheck `Disable implicit OAuth` | ||
|
||
## License | ||
|
||
``` | ||
MIT License | ||
Copyright (c) 2018 Nikola Jakšić | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.2.61' | ||
|
||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.1.4' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx1536m | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Wed Aug 29 09:11:57 CEST 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip |
Oops, something went wrong.