Application Only Authentication - Error Code 86 “This method requires a GET or HEAD”



I am trying to fetch tweets for using application only bearer token which I got using consumer key and consumer secret successfully. But I am not able to fetch the tweets. This is my code:

public class SearchTweetsTask extends AsyncTask<String, Void, String> {

    private static final String TWITTER_HOST = "";
    private static final String TWITTER_USER_AGENT = "TwitterMotion User Agent";

    private Logger logger = Logger.getLogger();

    protected String doInBackground(String... tokens) {
        String endPointUrl = tokens[0];
        HttpsURLConnection urlConnection = null;

        try {
            urlConnection = getHTTPSConnection("GET", endPointUrl);
                    "Bearer " + APPLICATION_ONLY_BEARER_TOKEN);

            String jsonResponse = readResponse(urlConnection);

            return responseAsJsonObject.toString();
        catch (Exception ex) {
            return null;
        finally {
            if (urlConnection != null) {

    protected void onPostExecute(String asyncTaskResult) {

    public static HttpsURLConnection getHTTPSConnection(String requestMethod, String endpointUrl)
            throws IOException {
        URL url = new URL(endpointUrl);
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.setRequestProperty("Host", TWITTER_HOST);
        connection.setRequestProperty("User-Agent", TWITTER_USER_AGENT);
        return connection;

    public static String readResponse(HttpsURLConnection connection) throws IOException {
        BufferedReader bufferedReader = null;
        try {
            StringBuilder stringBuilder = new StringBuilder();
            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line + System.getProperty("line.separator"));
            return stringBuilder.toString();
        catch (IOException ex) {
            throw ex;
        finally {
            if (bufferedReader != null) {

Inside readRequest() method, the connection object is not working as expected. I checked connection.getResponseCode() and its returning 400 and connection.getErrorStream() is returning Error Code 86 “This method requires a GET or HEAD”.

I tried with cURL on from command prompt and it worked perfect.

curl -X GET \
  '' \
  -H 'Authorization: Bearer <Application Only Bearer Token>' \
  -H 'Cache-Control: no-cache' \
  -H 'Host:' \
  -H 'User-Agent: TwitterMotion User Agent'

Please help me. Its getting very frustrating


As stated here, the httpCon.setDoOutput(true) implicitly set the request method to POST because that’s the default method whenever you want to send a request body.

If you want to use GET, remove that line.


Hi @Kaidul - Since you were able to resolve this, I’m closing this thread.

Thanks for being a community member and using the forums!