在Android中集成Instagram基本显示API [英] integrate instagram basic display api in android

查看:79
本文介绍了在Android中集成Instagram基本显示API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Instagram Basic Display API从我的应用程序获取authorization_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();
            }
        });
response中,我收到新的登录请求,但我没有被重定向到Instagram。 这是我的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}

注意:我的请求URL在Chrome中运行良好,我被重定向到包含authorization_code的新URL,但我无法在我的应用程序中执行此操作。

请指引我。

谢谢

主体

您需要将URL(";https://api.instagram.com/oauth/authorize";+推荐答案_str)加载到Web视图中,而不是使用Retrofit来调用它。

将其加载到网页视图后,它将打开Instagram登录页面,您需要在其中输入用户名和密码并登录。

然后,您将需要重写WebViewClientshoudOverrideUrlLoding方法,并查找您的redirect_uri+";/?code";并从此处提取令牌。

这篇关于在Android中集成Instagram基本显示API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆