Danielle
Danielle

Reputation: 1

MalformedURLException on Response in Android Studio Java

I am getting a MalformedURLException in logcat when I run my application. I am new to app development and used/modified code on the OAuth from GitHub. The Runnable is within a button press as well. Any ideas how to get this to function properly? Thanks!

                    try {
                        response = service.execute(request);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (ExecutionException e) {
                        throw new RuntimeException(e);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }

Rest of code

private final OAuth20Service service = new ServiceBuilder(clientId)
            .apiSecret(clientSecret)
            .defaultScope("sleep").responseType("code").callback(callbackURL).build(FitbitApi20.instance());
execService.execute(new Runnable() {
                @Override
                public void run() {
                    final OAuth2AccessToken oauth2AccessToken;

                    byte[] data = new byte[0];
                    try {
                        data = code.getBytes("UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException(e);
                    }
                    String base64code = Base64.encodeToString(data, Base64.DEFAULT);


                    try {
                        oauth2AccessToken = service.getAccessToken(code);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (ExecutionException e) {
                        throw new RuntimeException(e);
                    }

                    final FitBitOAuth2AccessToken accessToken = (FitBitOAuth2AccessToken) oauth2AccessToken;

                    final OAuthRequest request = new OAuthRequest(Verb.GET, code);
                    request.addParameter("client_id", clientId);
                    request.addParameter("client_secret", clientSecret);
                    request.addParameter("redirect_uri", callbackURL);
                    request.addParameter("scope", "sleep");
                    request.addParameter("request type", "code");
                    request.addParameter("Authorization", "Basic" + base64code);
                    request.addHeader("x-li-format", "json");

                    service.signRequest(accessToken, request);

                    final TextView fboutputTV = (TextView) findViewById(R.id.fbOutput);

                    Response response;
                    String concatRequest = "";

                    try {
                        response = service.execute(request);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (ExecutionException e) {
                        throw new RuntimeException(e);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }

                    try {
                        concatRequest = (String) (response.getCode() + " " + response.getBody());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }

I tried to find other resources on implementation but I am not seeing anything new enough to be helpful or it is not based in Android Studio.

Upvotes: 0

Views: 33

Answers (1)

Danielle
Danielle

Reputation: 1

Figure it out. This line was incorrect.

final OAuthRequest request = new OAuthRequest(Verb.GET, code);

Should have been: final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_URL);

Upvotes: 0

Related Questions