0

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.

asked Mar 24, 2023 at 9:52

1 Answer 1

0

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);

answered Mar 24, 2023 at 13:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.