如何从https://www.fitbit.com/oauth2/authorize获取代码

时间:2017-06-01 13:31:17

标签: android fitbit

我引用了https://dev.fitbit.com/apps/oauthinteractivetutorial链接来获取Android应用中的访问令牌。

第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代码中尝试过如下,但没有得到预期的结果。任何人都可以帮我这个吗?

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

1 个答案:

答案 0 :(得分:0)

这是固定的。在下面找到答案,我使用Webview

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

        });