title: Unable to retrieve data using generated accesstoken. everytime got 403 error code
body: <p>I am able to generate access token and store it. But I am Unable to get data using this access token. so could anyone suggest me how to set this access token in the header field. I am developing application in android. All time when i request for profile endpoint it gives me 403 error. </p>
  
  <p>my code for setting authorization header is as follow:
   con.setRequestProperty("Authorization","Bearer "+accesstoken);
  where con is URLConnection object.</p>
  
  <p>And also apart from this which headers I need to set for con object to make successful request.</p>
  
  <p>Any type of help would be appreciated. Thanks in advance.</p>
  
  <p>Here is tha class  for getting profile data:</p>
  
  <pre><code> public class ProfileRequestActivity extends Activity {
      MyUtility utility=new MyUtility(this);
      String urlString="https://platform.lifelog.sonymobile.com/v1/users/me";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          Log.d("pROFILE rEQUESt", "true");
          getProfile();
      }
      public void getProfile()
      {
  
          RequestPackage pkg=new RequestPackage();
          pkg.setUri(urlString);
          pkg.setMethod("GET");
          HTTPManager manager=new HTTPManager(pkg);
          HttpURLConnection con=manager.doConnection();
          Log.d("Access Token",utility.readPrefernce("access_token") );
          con.setRequestProperty("Accept-Charset" , "utf-8");
          con.setRequestProperty("Authorization", "Bearer "+utility.readPrefernce("access_token"));
          con.setRequestProperty("Accept", "application/json");
          //con.setDoInput(true);
          //con.setDoOutput(true);
          con.setRequestProperty("Accept-Encoding", "gzip");
          //con.setRequestProperty("Content-Encoding", "gzip");
          ExtractProfile task=new ExtractProfile();
          task.execute(con);
  
  
  
  
      }
  
  
      public class ExtractProfile extends AsyncTask&lt;HttpURLConnection, Void, Void&gt;
      {        
          @Override
          protected Void doInBackground(HttpURLConnection... params) 
          {
             int responseCode=0;
             //String data="";
          try {
              responseCode = params[0].getResponseCode();
              Map&lt;String,List&lt;String&gt;&gt; headerMap=params[0].getHeaderFields();
              Log.d("MAP",headerMap.toString());
               Log.d("profile response code",""+responseCode);
               Log.d("Header:",params[0].getRequestProperty("Authorization"));
              //data=params[0].getResponseMessage();
               BufferedReader reader;
              if (responseCode == HttpURLConnection.HTTP_OK)
              reader = new BufferedReader(new InputStreamReader(params[0].getInputStream()));
              else
              reader = new BufferedReader(new InputStreamReader((params[0].getErrorStream())));   
              String line;
              StringBuilder data=new StringBuilder();
              while((line=reader.readLine())!=null)
              {
                  data.append(line);
              }
              Log.d("data",data.toString());
  
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
            // Log.d("Data",data);
              return null;
          }
      }
  
  
  
  }
  
  
      Here is the helper class:
  
      public class RequestPackage {
  
          String uri="";
          String method="GET";
          Map&lt;String,String&gt; params=new HashMap&lt;String, String&gt;();
          public String getUri() {
              return uri;
          }
          public void setUri(String uri) {
              this.uri = uri;
          }
          public String getMethod() {
              return method;
          }
          public void setMethod(String method) {
              this.method = method;
          }
          public Map&lt;String, String&gt; getParams() {
              return params;
          }
          public void setParams(Map&lt;String, String&gt; params) {
              this.params = params;
          }
          public void setParam(String key,String value)
          {
              params.put(key, value);
          }
  
          public String getEncodedParams()
          {
              StringBuilder sb=new StringBuilder();
              for(String key:params.keySet())
              {
                  String value=null;
                  try {
                      value = URLEncoder.encode(params.get(key),"UTF-8");
                  } catch (UnsupportedEncodingException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  params.put(key, value);
                  if(sb.length()&gt;0)
                  {
                      sb.append("&amp;");
                      //sb.append(key+"=");
                  }
                  sb.append(key+"="+value);
              }
  
              return sb.toString();
          }
      }
  
  
      public class HTTPManager {
          RequestPackage pkg;
  
          public HTTPManager(RequestPackage p)
          {
              pkg=p;
          }
  
          public HttpURLConnection doConnection()
          {
              URL url;
              HttpURLConnection con=null;
              BufferedReader reader;
              String uri=pkg.getUri();
              Log.d("URI",uri);
              try {
                  if(pkg.getMethod().equals("GET"))
                  {
                      if(pkg.getParams().size()!=0)
                      uri+="?"+pkg.getEncodedParams();
                  }   
                  Log.d("Request Package URI",uri);
                  url = new URL(uri);         
                  con=(HttpURLConnection) url.openConnection();
                  con.setRequestMethod(pkg.getMethod());
                  //con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                  if(pkg.getMethod().equals("POST"))
                  {
                      con.setDoOutput(true);
                      con.setDoInput(true);
                      OutputStreamWriter writer=new OutputStreamWriter(con.getOutputStream());
                  //  Log.d("ENCODED PARAMETER",uri+"  "+pkg.getEncodedParams());
                      writer.write(pkg.getEncodedParams());
                      writer.flush();
                  }
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              Log.d("OUT CON",con.toString());
              return con;     
          }
  
          static public String readData(HttpURLConnection con)
          {
      //      Log.d("IN CON",con.toString());
      //          String token = con.getHeaderFields();
      //          return token;
  
  
              try {
                  //Log.d("Connection",con.toString());
                  //Log.d("Response",""+con.getResponseCode());
                  BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                  StringBuilder sb=new StringBuilder();
                  String line;
                  while((line=reader.readLine())!=null)
                  {
                      sb.append(line);
                  }
                  return sb.toString();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  return null;
              }
  
  
          }
  
      }
  </code></pre>