Callback URL example with Instagram OAuth

suggest change

One of the use cases of callback URLs is OAuth. Let us do this with an Instagram Login: If the user enters their credentials and clicks the Login button, Instagram will validate the credentials and return an access_token. We need that access_token in our app.

For our app to be able to listen to such links, we need to add a callback URL to our Activity. We can do this by adding an <intent-filter/> to our Activity, which will react to that callback URL. Assume that our callback URL is appSchema://appName.com. Then you have to add the following lines to your desired Activity in the Manifest.xml file:

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="appName.com" android:scheme="appSchema"/>

Explanation of the lines above:

Now, in order to get the contents of the URL in your Activity, you need to override the onResume() method as follows:

@Override 
public void onResume() { 
    // The following line will return "appSchema://appName.com".
    String CALLBACK_URL = getResources().getString(R.string.insta_callback);
    Uri uri = getIntent().getData();
    if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
        String access_token = uri.getQueryParameter("access_token");
    }
    // Perform other operations here.
}

Now you have retrieved the access_token from Instagram, that is used in various API endpoints of Instagram.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Callback URL:
* Callback URL example with Instagram OAuth

Table Of Contents
2 Gradle
5 Intent
17 Service
19 WebView
31 SQLite
35 Glide
37 Dialog
38 ACRA
44 Handler
53 Toast
63 Menu
65 Picasso
70 Volley
71 Widgets
78 Realm
90 Spinner
95 OkHttp
108 TextView
109 ListView
111 Loader
118 Xposed
119 Security
121 ImageView
123 Doze Mode
127 Callback URL
130 Drawables
131 Colors
134 Fresco
139 AdMob
145 Keyboard
146 Button
150 EditText
155 Vk SDK
163 ExoPlayer
169 XMPP
175 OpenCV
177 Threads
184 ORMLite
186 TabLayout
190 LruCache
192 Zip files
194 Fastlane
199 FileIO
202 Moshi
210 VideoView
216 Paint
218 ProGuard
226 CleverTap
228 ADB shell
229 Ping ICMP
230 AIDL
234 Context
240 JCodec
242 Okio
249 FuseView
254 Looper
261 Fastjson
263 Jackson
267 Smartcard