2017-06-01 56 views
0

我指的是https://dev.fitbit.com/apps/oauthinteractivetutorial獲取Android App中的訪問令牌的鏈接。如何從https://www.fitbit.com/oauth2/authorize獲取代碼

第1步:

在這裏,我硬編碼的註冊應用程序的詳細信息。

String urls = "https://www.fitbit.com/oauth2/authorize?" + 
          "response_type=code" + 
          "&client_id=228K7X" + 
          "&expires_in=2592000" + 
          "&scope=profile%20settings%20weight" + 
          "&redirect_uri=http://www.google.com/" ; 

從這個環節,我應該得到Code.If我複製過去的這個瀏覽器我得到這樣的代碼

http://www.google.com/碼= e800eef2374bd6c1f5cc5e8dab65d4d4bff60406#=


我試着像下面android的代碼,但沒有得到預期的result.Can任何一個可以幫助我這個?

     URL url = new URL(urls); 
         HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 
         connection.setRequestMethod("POST"); 
         connection.setDoInput(true); 
         connection.connect(); 
        InputStream inputStream = connection.getInputStream(); 
        BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); 
+0

什麼是你希望要回到底是什麼?一個JSON對象? –

回答

0

這是Fixed.Find回答以下,我使用網頁視圖

webView = (WebView) findViewById(R.id.webView); 
webView.getSettings().setJavaScriptEnabled(true); 

     String urls = "https://www.fitbit.com/oauth2/authorize?" + 
       "response_type=code" + 
       "&client_id=228K7X" + 
       "&expires_in=2592000" + 
       "&scope=profile%20settings%20weight" + 
       "&redirect_uri=http://www.google.com/" ; 

     Log.i(TAG," urls ? "+urls); 

     webView.loadUrl(urls); 
     webView.setWebViewClient(new WebViewClient(){ 

      @Override 
      public void onPageStarted(WebView view, String url, Bitmap favicon) { 
       super.onPageStarted(view, url, favicon); 
      } 

      @Override 
      public void onPageFinished(WebView view, String url) { 
       super.onPageFinished(view, url); 

       Log.i(TAG," onPageFinished ? "+url); 
      } 

     });