如何在instagram api中关注或取消关注用户(java,隐式方式)

时间:2017-09-20 12:00:27

标签: java api instagram

See This Image

我试图在java中使用Instagram api关注或取消关注用户 这是我的代码:

    public static void main(String[] args) {
                       String urlString = "https://api.instagram.com/v1/users/"+USERID+"/relationship?access_token="+TOKEN; // URL to call

      String data = (URLEncoder.encode("action:unfollow")); //data to post
            OutputStream out = null;
            try {
                URL url = new URL(urlString);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setDoOutput(true);
            urlConnection.setDoInput(true);
urlConnection.setRequestMethod("POST");
                out = new BufferedOutputStream(urlConnection.getOutputStream());
                BufferedWriter writer = new BufferedWriter (new OutputStreamWriter(out, "UTF-8"));
                writer.write(data);
                writer.flush();
                writer.close();
                out.close();
                urlConnection.connect();

            } catch (Exception e) {
                System.out.println(e.getMessage());
            }

    }

我希望通过此代码取消关注用户,但这不起作用 提前谢谢

编辑:
已解决!

应删除URLEncoder,并使用=代替:
        字符串数据=(" action = unfollow"); //要发布的数据 当我添加inputString代码时效果很好!

2 个答案:

答案 0 :(得分:0)

我认为你需要在URLEncoder.encode()上传递'action = unfollow'

答案 1 :(得分:0)

请注意,Instagram不再提供新的“关系”权限。你有这个权限吗?我想听听你是如何使用它的 instagram.com/developer/authorization /