Instagram API


Source link: https://github.com/sayyam/instagramapi

Instagram API

A wrapper on instagram API for android.

Download

Gradle:

maven {
 url 'https://dl.bintray.com/sayyam/maven' 
}
  compile 'com.github.sayyam:instagramapi:0.1.0'

Maven:

<dependency>
<groupId>com.github.sayyam</groupId>
<artifactId>instagramapi</artifactId>
<version>0.1.0</version>
<type>pom</type> </dependency>

Usage

Include Application's Client Id and Redirect Uri:

Add following meta tags in <application> tag of your AndroidManifest.

  <meta-data
  android:name="com.instagram.instagramapi.InstagramAppClientId"
  android:value="PUT-YOUR-CLIENT-ID-HERE" />
 <meta-data
  android:name="com.instagram.instagramapi.InstagramAppRedirectURL"
  android:value="PUT-YOUR-REDIRECT-URI-HERE" />

You can get above credentials from Instagram Developrs Portal.

Initiate the authorization process:

You can start the InstagramEngine in two different ways:

  1. Intent
  2. InstagramLoginButton

1- Initiate the authorization process via Intent:

Create an intent
  String[] scopes = {
InstagramKitLoginScope.BASIC, InstagramKitLoginScope.COMMENTS
}
;

Intent intent = new Intent(SampleActivity.this, InstagramAuthActivity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |

  Intent.FLAG_ACTIVITY_SINGLE_TOP);

 intent.putExtra(InstagramEngine.TYPE, InstagramEngine.TYPE_LOGIN);

//add scopes if you want to have more than basic access
intent.putExtra(InstagramEngine.SCOPE, scopes);

startActivityForResult(intent, 0);
Handle Login Result
  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

 super.onActivityResult(requestCode, resultCode, data);

  switch (requestCode) {

  case 0:

 if (resultCode == RESULT_OK) {

  Bundle bundle = data.getExtras();

  if (bundle.containsKey(InstagramKitConstants.kSessionKey)) {

IGSession session = (IGSession) bundle.getSerializable(InstagramKitConstants.kSessionKey);

Toast.makeText(SampleActivity.this, "Woohooo!!! User trusts you :) " + session.getAccessToken(),

 Toast.LENGTH_LONG).show();

 
}

}

break;

 
}

 
}

2- Initiate the login process via InstagramLoginButton:

Add InstagramLoginButton in your layout
  <com.instagram.instagramapi.widgets.InstagramLoginButton

 android:id="@+id/instagramLoginButton"

 android:layout_width="200dp"

 android:layout_height="55dp"

 android:text="Login Button" />

#####Initialize InstagramLoginButton in your Activity

  String[] scopes = {
InstagramKitLoginScope.BASIC, InstagramKitLoginScope.COMMENTS
}
;

 InstagramLoginButton instagramLoginButton = (InstagramLoginButton) findViewById(R.id.instagramLoginButton);
  instagramLoginButton.setInstagramLoginCallback(instagramLoginCallbackListener);
  //if you dont specify scopes, you will have basic access.  instagramLoginButton.setScopes(scopes);
 
Handle Login callback
  InstagramLoginCallbackListener instagramLoginCallbackListener = new InstagramLoginCallbackListener() {

 @Override

 public void onSuccess(IGSession session) {

Toast.makeText(SampleActivity.this, "Wow!!! User trusts you :) " + session.getAccessToken(),

 Toast.LENGTH_LONG).show();

  
}

  @Override

 public void onCancel() {

  Toast.makeText(SampleActivity.this, "Oh Crap!!! Canceled.",

 Toast.LENGTH_LONG).show();

  
}

  @Override

 public void onError(InstagramException error) {

  Toast.makeText(SampleActivity.this, "User does not trust you :(\n " + error.getMessage(),

 Toast.LENGTH_LONG).show();

  
}

}
;

Fetch User details:

Get user details via getUserDetails()
InstagramEngine.getInstance(SampleActivity.this).getUserDetails(instagramUserResponseCallback);
Handle Response in callback
  InstagramAPIResponseCallback<IGUser> instagramUserResponseCallback = new InstagramAPIResponseCallback<IGUser>() {

 @Override

 public void onResponse(IGUser responseObject, IGPagInfo pageInfo) {

Toast.makeText(SampleActivity.this, "Username: " + responseObject.getUsername(),

 Toast.LENGTH_LONG).show();

 
}

  @Override

 public void onFailure(InstagramException exception) {

  Log.v("SampleActivity", "Exception:" + exception.getMessage());

 
}

}
;

Logout user:

InstagramEngine.getInstance(SampleActivity.this).logout();

Exception Handling:

In case of exceptions like insufficient scope or invalid parameters you will get InstagramException in onFailure() of your callback.

InstagramAPIResponseCallback<IGUser> instagramUserResponseCallback = new InstagramAPIResponseCallback<IGUser>() {

...
@Override
public void onFailure(InstagramException exception) {

 Log.v("Exception", "Exception:" + exception.getMessage());

 
}

}

License

Copyright 2016 Sayyam.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitation under the License.

Resources

Getting location updates requires lots of bolierplate code in Android, You need to take care of

  • Google Play services availablity Check
  • Update Google play Service Dialog
  • Creation of GoogleApiClient and its callbacks connected,disconnected etc.
  • Stopping and releasing resources for location updates
  • Handling Location permission scenarios
  • Checking Location services are On or Off
  • Getting lastknown location is not so easy either
  • Fallback to last known location if not getting location after certain duration

Android-EasyLocation does all this stuff in background, so that you can concentrate on your business logic than handling all above

Stops the user from keep using the App after a period of time based on app build time. Mainly to have control preview versions handed out using e.g.: hockeyapp or fabric.

Simple lifecycle for your MVWhatever on Android. No kidding.

A simple Bash script to record screen.

This library provides a wave loading animation as a Drawable.

A quick settings tile to quickly toggle "Don't keep activities".

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes