Solution 1 :
You’ll need to load the URL(“https://api.instagram.com/oauth/authorize” + body_str) into a webview and not use retrofit to call it.
After you load it into the webview it will open up instagram login page where you need to enter your username and password and login.
You will then need to override the shouldOverrideUrlLoading method of the WebViewClient and look for your redirect_uri+”/?code” and extract the token from here.
Problem :
I want to use Instagram Basic Display API to get authorization_code
from my app but it does not work.
I used this code:
String client_id = "my_client_id";
String oAuthUrl = "https://testsite.com/auth/";
String body_str = "?client_id=" + client_id +
"&redirect_uri=" + oAuthUrl +
"&scope=user_profile,user_media" +
"&response_type=code";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.instagram.com/oauth/authorize" + body_str).get().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String ans = response.toString();
}
});
In response
, I get a new log in request but I didn’t get redirected to Instagram.
Here’s my response
:
Response{protocol=h2, code=200, message=, url=https://www.instagram.com/accounts/login/?force_authentication=1&enable_fb_login=1&platform_app_id=my_client_id&next=/oauth/authorize%3Fclient_id%3Dmy_client_id%26redirect_uri%3Dhttps%3A//testsite.com/auth/%26scope%3Duser_profile%2Cuser_media%26response_type%3Dcode}
Note: My request url works well in chrome and I get redirected to new url containing authorization_code
, but I can’t do it inside my application.
Please guide me.
Thanks