如何从 https://www.fitbit.com/oauth2/authorize 获取获取代码
How to get Get Code from https://www.fitbit.com/oauth2/authorize
我指的是 https://dev.fitbit.com/apps/oauthinteractivetutorial link 在 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/" ;
从这个link我应该得到Code.If我在浏览器中复制过去我得到这样的代码
http://www.google.com/?code=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));
下面是Fixed.Find的回答,我使用的是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);
}
});
我指的是 https://dev.fitbit.com/apps/oauthinteractivetutorial link 在 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/" ;
从这个link我应该得到Code.If我在浏览器中复制过去我得到这样的代码
http://www.google.com/?code=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));
下面是Fixed.Find的回答,我使用的是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);
}
});