当前位置: 首页 > news >正文

一个网站怎么推广宿迁手机网站建设公司

一个网站怎么推广,宿迁手机网站建设公司,广西核心关键词seo报价,汉阳网站建设公司吐槽 最近在自研开发一款有关读取健康数据的APP 但是数据来源非常稀少#xff0c;申请了市面上所有的国内厂商的手环api都被拒了#xff08;因为是个人开发#xff09; 找了很久发现fitbit有开源的api于是淘了个fitbit的手表开始开发 Web API (fitbit.com) 在上述连接可…吐槽 最近在自研开发一款有关读取健康数据的APP 但是数据来源非常稀少申请了市面上所有的国内厂商的手环api都被拒了因为是个人开发 找了很久发现fitbit有开源的api于是淘了个fitbit的手表开始开发 Web API (fitbit.com) 在上述连接可以按步骤使用api 不知道是不是因为我英语不好的原因总是感觉开发文档写的很拉想找找大佬的实例代码跑一下发现要么找不到要么直接没法用。 没办法只能手搓。。。 以下是项目结构 pom dependenciesdependencygroupIdcom.anXin/groupIdartifactIdanXin-utils/artifactIdversion3.6.3/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdscopetest/scope/dependencydependencygroupIdorg.apache.httpcomponents/groupIdartifactIdhttpclient/artifactIdversion4.5.13/version/dependencydependencygroupIdcom.google.code.gson/groupIdartifactIdgson/artifactId/dependency/dependencies utils是我自己的工具类其实只用到了base64加密随便搜一个替换就行 思路 首先注册一个应用程序这个很简单不教学了主要是获取token等关键信息因为这些api都基于这些关键信息 他的授权码请求URL https://www.fitbit.com/oauth2/authorize?client_idABC123response_typecode code_challengecode_challengecode_challenge_methodS256 scopeactivity%20heartrate%20location%20nutrition%20oxygen_saturation%20profile %20respiratory_rate%20settings%20sleep%20social%20temperature%20weight 但是会跳出以下授权页面 抓包发现是全部授权后会重定向因此直接模拟浏览器重定向请求在下面的代码已经给出 即可获取授权码来获取token 要注意的是请求一定要携带cookie不然会自动重定向到登录 实现 service定义接口 实现类先预留以下属性 private String clientId你的客户端id;private String clientSecret你的客户端秘钥;private String scopeactivity heartrate location nutrition profile settings sleep social weight;private String userAuthorizationUrihttps://www.fitbit.com/oauth2/authorize;private String accessTokenUrihttps://api.fitbit.com/oauth2/token;private String code;private String access_token;private String refresh_token;private String token_type;private String user_id; 接下来实现接口 try {// 创建CookieStore并设置CookieCookieStore cookieStore new BasicCookieStore();BasicClientCookie cookie new BasicClientCookie(Cookie, 自己在请求头那里复制); // 替换为实际的Cookie信息cookie.setDomain(www.fitbit.com); // 设置Cookie的作用域cookie.setPath(/); // 设置Cookie的路径cookieStore.addCookie(cookie);CloseableHttpClient httpClient HttpClients.custom().setDefaultCookieStore(cookieStore).build();String postData client_idclientIdresponse_typecodescopeactivityheartratelocationnutritionoxygen_saturationprofilerespiratory_ratesettingssleepsocialtemperatureweightstatepromptnone;HttpPost httpPost new HttpPost(userAuthorizationUri);// 设置POST请求的Content-TypehttpPost.setHeader(Content-Type, application/x-www-form-urlencoded);// 设置POST请求的参数StringEntity entity new StringEntity(postData, StandardCharsets.UTF_8);httpPost.setEntity(entity);CloseableHttpResponse response httpClient.execute(httpPost);int statusCode response.getStatusLine().getStatusCode();if (statusCode302){Header locationHeader response.getFirstHeader(Location);if (locationHeader ! null) {String redirectURL locationHeader.getValue();System.out.println(以下为fitbit服务信息);System.out.println(重定向的路径 redirectURL);coderedirectURL.substring(redirectURL.indexOf()1).split(#)[0];System.out.println(Authorize为code);} else {System.out.println(未找到重定向路径);}}else {log.error(fitbit获取code失败);}CloseableHttpClient tokenHttpClient HttpClients.createDefault();String tokenPostData grant_typeauthorization_codecodecode;HttpPost tokenHttpPost new HttpPost(accessTokenUri);// 设置POST请求的Content-TypetokenHttpPost.setHeader(Authorization,Basic Base64Utils.encode((clientId:clientSecret).getBytes()));tokenHttpPost.setHeader(Content-Type, application/x-www-form-urlencoded);// 设置POST请求的参数StringEntity tokenEntity new StringEntity(tokenPostData, StandardCharsets.UTF_8);tokenHttpPost.setEntity(tokenEntity);CloseableHttpResponse tokenResponse tokenHttpClient.execute(tokenHttpPost);BufferedReader reader new BufferedReader(new InputStreamReader(tokenResponse.getEntity().getContent()));StringBuilder jsonResponse new StringBuilder();String line;while ((line reader.readLine()) ! null) {jsonResponse.append(line);}System.out.println(返回的JSON数据 jsonResponse.toString());Gson gson new Gson();MapString,Object map gson.fromJson(jsonResponse.toString(), Map.class);access_token (String) map.get(access_token);refresh_token (String) map.get(refresh_token);token_type (String) map.get(token_type);user_id (String) map.get(user_id);System.out.println(access_token为access_token);System.out.println(refresh_token为refresh_token);System.out.println(token_type为token_type);System.out.println(user_id为user_id);System.out.println(fitbit服务信息结束);}catch (Exception e){log.error(获取fitbit的token失败);e.printStackTrace();} 手搓成功
http://www.tj-hxxt.cn/news/221185.html

相关文章:

  • 企业网站升级app科技产品网站建设
  • 专业北京网站建设公司排名湛江网站制作江网站制作
  • 化妆品企业网站建设的策划方案wordpress 比较
  • 网站做好第二年要多少钱国内哪个网站是做电子元器件的
  • 湖南做网站哪家好服装设计手绘
  • 做网站需注意事项医院 网站建设 新闻
  • 网站建设商业眉山建设中等职业技术学校 网站
  • 怎么建设网站挣钱河源北京网站建设
  • 开封做网站睿艺美建设行业证书全国联网查询
  • 如何将html发布到网站网站经营性备案需要什么资料
  • 冷饮网站开发背景意义秦皇岛城乡建设局
  • 宜昌网站开发网站建设服务合约
  • 永久免费网站虚拟主机wordpress用户头像插件
  • 公益网站建设郑州开发小程序平台
  • 服务器iis做网站杭州网站开发后端招
  • 汽车专业网站网站建设费用包括哪些
  • 请问婚庆网站建设该怎么做呢做选择的网站首页
  • 花生壳怎么建设购物网站教育网站制作公司
  • 网站开发简述100个最好的微信小程序
  • 襄阳谷城网站建设免费seo软件推荐
  • 淘宝内部卷怎么做网站商务邮箱注册
  • 做试卷的网站编程一小时网站
  • 西安外贸网站建设wordpress邮件发送类
  • 自己如何制作一个网页seo软件开发
  • 自己做网站需要多少资金wordpress菜单手机显示下拉
  • 怎么看网站用什么平台做的网页设计项目模板代码
  • 消防网站建设的风格项目立项流程
  • 网站建设公司排行百度怎样做网站
  • 访问自己做的网站中石化工建设宁波分公司网站
  • 沣东新城开发建设集团有限公司网站xampp如何安装wordpress