Android Callback URL edit

Callback URL example with Instagram OAuth

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
Callback URL example with Instagram OAuth

Table Of Contents
39 ACRA
64 Menu
112 Loader
119 Xposed
128 Callback URL
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close