【问题标题】:integrate instagram basic display api in android在android中集成instagram基本显示api
【发布时间】:2020-06-07 15:13:32
【问题描述】:

我想使用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}

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

请指导我。

谢谢

【问题讨论】:

    标签: android instagram-api


    【解决方案1】:

    您需要将 URL("https://api.instagram.com/oauth/authorize" + body_str) 加载到 web 视图中,而不是使用改造来调用它。

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

    然后您需要覆盖 WebViewClientshouldOverrideUrlLoading 方法并查找您的 redirect_uri+"/?code" 并提取令牌从这里开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      相关资源
      最近更新 更多