-1

I have my bearerToken and userID as per Twitter instructions https://dev.twitter.com/docs/auth/application-only-auth and I want t get a list of followers.

I'm getting error 86, which isn't on the list of error codes https://dev.twitter.com/docs/error-codes-responses

Any pointers would be appreciated.

public String getTwitterFriends(String userID, String bearerToken) {
    // Use App Bearer token to get public friends
    String answer = "";
    String param = "count=5000&cursor=-1&user_id=" + userID;
    HttpURLConnection connection = null;
    try {
        // String request =
        // "https://api.twitter.com:443/1.1/friends/ids.json?" + param;
        String request = "https://api.twitter.com/1.1/friends/ids.json?"
                + param;
        URL url = new URL(request);
        connection = (HttpURLConnection) url.openConnection();
        System.setProperty("http.keepAlive", false ? "true" : "false");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("GET");
        // connection.setRequestProperty("Host", "api.twitter.com" +
        // ":443");
        connection.setRequestProperty("Host", "api.twitter.com");
        connection.setRequestProperty("Accept", "*/*");
        connection.setRequestProperty("Authorization", "Bearer "
                + bearerToken);
        connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded;charset=utf-8");
        connection.setRequestProperty("User-Agent", "UnhappyChappy");
        // connection.setRequestProperty("Accept-Encoding", "gzip");
        // connection.setRequestProperty("Content-Length", "" +
        // Integer.toString(param.getBytes().length));
        connection.setUseCaches(false);
        DataOutputStream wr = new DataOutputStream(
                connection.getOutputStream());
        // wr.writeBytes(param);
        wr.flush();
        wr.close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        String line;
        StringBuilder str = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
            str.append(line);
        }
        reader.close();
        connection.disconnect();
        answer = str.toString();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println(answer);
    return answer;
}   
0

It was the way I issued the GET. I had to go to a lower level on App Engine and use FetchOptions This worked for me, hopefully it will help someone else.

        URL url = new URL(request);

        HTTPRequest req = new HTTPRequest(url, HTTPMethod.GET);
        req.addHeader(new HTTPHeader("Authorization", "Bearer " + bearerToken));

        HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(req);
        System.out.println(new String(response.getContent()));

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.