title: Android Volley Request with OAuth2 Authorization
body: <p>I need to call a REST API that simply updates the value of a field in the database. To do this, I use the following Volley request, but it return an Unexpected response code 401 (unauthorized), it seems as if the headers for OAuth2 authorization get ignored. I checked the access token value and it is there correctly. What's my mistake?</p>
  
  <pre><code>private void sendRegistrationTokenToServer(final String token) {
           // user ID taken from SharedPreferences
           final String id = Integer.toString(SharedPrefManager.getInstance(this).getUserId());
  
           StringRequest stringRequest = new StringRequest
              (
               Request.Method.PUT,
               Constants.URL_GCM_TOKEN+"/"+ Utils.base64Encode(id),
  
               new Response.Listener&lt;String&gt;()
                  {
                   @Override
                   public void onResponse(String s)
                      {
                       Intent registrationComplete = new Intent(REGISTRATION_TOKEN_SENT);
                       LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete);
                      }
                  },
  
               new Response.ErrorListener()
                  {
                   @Override
                   public void onErrorResponse(VolleyError volleyError)
                      {
                       Toast.makeText(getBaseContext(), "Unexpected error occurred when saving the GCM token for push notifications", Toast.LENGTH_LONG).show();
                      }
                  })
              {
               @Override
               protected Map&lt;String, String&gt; getParams() throws AuthFailureError
                  {
                   Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
  
                   params.put("gcm_token", token);
  
                   return params;
                  }
  
  
               @Override
               public Map&lt;String, String&gt; getHeaders() throws AuthFailureError
                  {
                   Map&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
  
                   headers.put("Content-Type", "application/json");
  
                   String bearer = "Bearer ".concat(SharedPrefManager.getInstance(getBaseContext()).getUserAccessToken());
  
                   headers.put("Authorization", bearer);
  
                   return headers;
                  }
              };
  
           App.getInstance().addToRequestQueue(stringRequest);
          }
  </code></pre>