I am trying to retrieve the data from my account by connecting to the Fitbit API. I have my app returning the Access Token I need to make the HTTP Request that returns the JSON but anything that I try, it returns an error. I have two Activities - MainActivity.java and TestActivity.java

In MainActivity.java I am simply opening a Chrome Custom Tab to direct the user to the Fitbit Authentication(Login) page. Once the user enters their details they are redirected back to the TestActivity.java as per the Fitbit API documentation. I am then printing the Acess Token which proves to me that it is connecting to the API. 

What I need to do it make an HTTP request to returns the sleep data in JSON format. I know how to do it in Java but I am unsure how to do it in Android using the AsyncTask way. Any help is appreciated! 

```
public class TestActivity extends AppCompatActivity {

String string;
String token;

@Override
protected void onNewIntent(Intent intent) {
    string = intent.getDataString();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    onNewIntent(getIntent());
    //Toast.makeText(TestActivity.this, string , Toast.LENGTH_LONG).show();
    Log.e("TAG", string);
    Log.e("TAG", string.substring(string.indexOf("&access_token")+14));

    token = string.substring(string.indexOf("&access_token")+14);

    Context context = getApplicationContext();
    Toast toast = Toast.makeText(context,"Access Token: "+ token,Toast.LENGTH_LONG );

    Log.i("TAG", "Access Token: "+ token);

    new JSONTask().execute("https://api.fitbit.com/1.2/user/-/sleep/date/2018-01-30.json");

}

public class JSONTask extends AsyncTask<String,String,String>
{

    @Override
    protected String doInBackground(String... params) {

        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try
        {
            URL url = new URL(params[0]);
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Authorization", "Bearer " + token);
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();

            InputStream stream = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(stream));

            StringBuffer buffer = new StringBuffer();

            String line = "";

            while((line = reader.readLine()) !=null)
            {
                buffer.append(line);
            }

            return buffer.toString();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;

    }

    @Override
    protected void onPostExecute(String s)
    {
        super.onPostExecute(s);
        Log.i("TAG", s);
    }
}

```