title: Login 404 Parse.com REST API Java
body: <p>We decided to build our own twitter login for aesthetic reasons rather than use ParseTwitterUtils.login(), and we are having to login through the REST API (unless someone has a better idea on how to get a session token for a user with twitterAuth). </p>
  
  <p>So currently it is set up as such: </p>
  
  <pre><code>private class ParseLogin extends AsyncTask&lt;String, String, Boolean&gt; {
  
      JSONObject authData;
      JSONObject wrapper;
  
      @Override
      protected void onPreExecute() {
          try {
              authData = new JSONObject();
              wrapper = new JSONObject();
              JSONObject twitterAuth = new JSONObject();
              twitterAuth.put("id", Long.toString(twitterUser.getId()));
              twitterAuth.put("screen_name", twitterUser.getScreenName());
              twitterAuth.put("consumer_key", CONSUMER_KEY);
              twitterAuth.put("consumer_secret", CONSUMER_SECRET);
              twitterAuth.put("auth_token", accessToken.getToken());
              twitterAuth.put("auth_secret", accessToken.getTokenSecret());
              authData.put("twitter", twitterAuth);
              wrapper.put("authData", authData);
  
  
          } catch (JSONException e)
          {
              e.printStackTrace();
          }
      }
      @Override
      protected Boolean doInBackground(String... args) {
          // Send the HttpPostRequest and receive a JSONObject in return
          JSONObject jsonObjRecv = JSONRequest.SendHttpGet("https://api.parse.com/1/users/", wrapper);
  
          return true;
      }
      @Override
      protected void onPostExecute(Boolean response) {
  
  
  
  
      }
  
  }
  </code></pre>
  
  <p>Which then in turns sends the login request to the REST API via here</p>
  
  <pre><code>public static JSONObject SendHttpPost(String URL, JSONObject jsonObjSend) {
  
      try {
          DefaultHttpClient httpclient = new DefaultHttpClient();
          HttpGetWithEntity httpPostRequest = new HttpGetWithEntity(URL);
  
          StringEntity se;
          se = new StringEntity(jsonObjSend.toString());
  
          // Set HTTP parameters
          httpPostRequest.setEntity(se);
          httpPostRequest.setHeader("X-Parse-Application-Id", APP KEY);
          httpPostRequest.setHeader("X-Parse-REST-API-Key", REST API KEY);
          httpPostRequest.setHeader("Accept", "application/json");
          httpPostRequest.setHeader("Content-type", "application/json");
  
          long t = System.currentTimeMillis();
          HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
          Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
  
          // Get hold of the response entity (-&gt; the data):
          HttpEntity entity = response.getEntity();
  
          if (entity != null) {
              // Read the content stream
              InputStream instream = entity.getContent();
              Header contentEncoding = response.getFirstHeader("Content-Encoding");
              if (contentEncoding != null &amp;&amp; contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                  instream = new GZIPInputStream(instream);
              }
  
              // convert content stream to a String
              String resultString= convertStreamToString(instream);
              Log.d("JSON RESULT", resultString);
              instream.close();
              resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]"
  
              // Transform the String into a JSONObject
              JSONObject jsonObjRecv = new JSONObject(resultString);
              // Raw DEBUG output of our received JSON object:
              Log.i(TAG,"&lt;JSONObject&gt;\n"+jsonObjRecv.toString()+"\n&lt;/JSONObject&gt;");
  
              return jsonObjRecv;
  </code></pre>
  
  <p>Any ideas on the 404?</p>
  
  <p>Edit: Fixed - Use /Users/ instead of /Login/ for 3rd party auth, changes from GET to POST</p>
  
  <pre><code>  private class ParseLogin extends AsyncTask&lt;String, String, Boolean&gt; {
  
      JSONObject authData;
      JSONObject wrapper;
  
      @Override
      protected void onPreExecute() {
          try {
              authData = new JSONObject();
              wrapper = new JSONObject();
              JSONObject twitterAuth = new JSONObject();
              twitterAuth.put("id", Long.toString(twitterUser.getId()));
              twitterAuth.put("screen_name", twitterUser.getScreenName());
              twitterAuth.put("consumer_key", CONSUMER_KEY);
              twitterAuth.put("consumer_secret", CONSUMER_SECRET);
              twitterAuth.put("auth_token", accessToken.getToken());
              twitterAuth.put("auth_token_secret", accessToken.getTokenSecret());
              authData.put("twitter", twitterAuth);
              wrapper.put("authData", authData);
  
  
          } catch (JSONException e)
          {
              e.printStackTrace();
          }
      }
      @Override
      protected Boolean doInBackground(String... args) {
          // Send the HttpPostRequest and receive a JSONObject in return
          JSONObject jsonObjRecv = JSONRequest.SendHttpGet("https://api.parse.com/1/users/", wrapper);
  
          return true;
      }
      @Override
      protected void onPostExecute(Boolean response) {
  
      }
  </code></pre>
  
  <p>And then the Get (which is actually a post, just need to changed the method name)</p>
  
  <pre><code>public static JSONObject SendHttpGet(String URL, JSONObject jsonObjSend) {
  
      try {
          DefaultHttpClient httpclient = new DefaultHttpClient();
          HttpPost httpPostRequest = new HttpPost(URL);
  
          StringEntity se;
          se = new StringEntity(jsonObjSend.toString());
  
          // Set HTTP parameters
          httpPostRequest.setEntity(se);
          httpPostRequest.setHeader("X-Parse-Application-Id", APP ID);
          httpPostRequest.setHeader("X-Parse-REST-API-Key", REST API KEY);
          httpPostRequest.setHeader("Accept", "application/json");
          httpPostRequest.setHeader("Content-type", "application/json");
          //httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression
  
          long t = System.currentTimeMillis();
          HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
          Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
  
          // Get hold of the response entity (-&gt; the data):
          HttpEntity entity = response.getEntity();
  
          if (entity != null) {
              // Read the content stream
              InputStream instream = entity.getContent();
              Header contentEncoding = response.getFirstHeader("Content-Encoding");
              if (contentEncoding != null &amp;&amp; contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                  instream = new GZIPInputStream(instream);
              }
  
              // convert content stream to a String
              String resultString= convertStreamToString(instream);
              Log.d("JSON RESULT", resultString);
              instream.close();
              resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]"
  
              // Transform the String into a JSONObject
              JSONObject jsonObjRecv = new JSONObject(resultString);
              // Raw DEBUG output of our received JSON object:
              Log.i(TAG,"&lt;JSONObject&gt;\n"+jsonObjRecv.toString()+"\n&lt;/JSONObject&gt;");
  
              return jsonObjRecv;
          }
  
      }
      catch (Exception e)
      {
          // More about HTTP exception handling in another tutorial.
          // For now we just print the stack trace.
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>