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

国际空间站搜索引擎营销优化策略有哪些

国际空间站,搜索引擎营销优化策略有哪些,iis v6 新建网站,成品短视频软件源码吐槽 最近在自研开发一款有关读取健康数据的APP 但是数据来源非常稀少,申请了市面上所有的国内厂商的手环api都被拒了(因为是个人开发) 找了很久发现fitbit有开源的api于是淘了个fitbit的手表开始开发 Web API (fitbit.com) 在上述连接可…

吐槽

最近在自研开发一款有关读取健康数据的APP

但是数据来源非常稀少,申请了市面上所有的国内厂商的手环api都被拒了(因为是个人开发)

找了很久发现fitbit有开源的api于是淘了个fitbit的手表开始开发

Web API (fitbit.com)

在上述连接可以按步骤使用api

不知道是不是因为我英语不好的原因,总是感觉开发文档写的很拉,想找找大佬的实例代码跑一下,发现要么找不到,要么直接没法用。

没办法只能手搓。。。

以下是项目结构

pom

<dependencies><dependency><groupId>com.anXin</groupId><artifactId>anXin-utils</artifactId><version>3.6.3</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.13</version></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency></dependencies>

utils是我自己的工具类,其实只用到了base64加密随便搜一个替换就行

思路

首先注册一个应用程序,这个很简单不教学了,主要是获取token等关键信息,因为这些api都基于这些关键信息

他的授权码请求URL

https://www.fitbit.com/oauth2/authorize?client_id=ABC123&response_type=code
&code_challenge=<code_challenge>&code_challenge_method=S256
&scope=activity%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 scope="activity heartrate location nutrition profile settings sleep social weight";private String userAuthorizationUri="https://www.fitbit.com/oauth2/authorize";private String accessTokenUri="https://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_id="+clientId+"&response_type=code&scope=activity+heartrate+location+nutrition+oxygen_saturation+profile+respiratory_rate+settings+sleep+social+temperature+weight&state&prompt=none";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 (statusCode==302){Header locationHeader = response.getFirstHeader("Location");if (locationHeader != null) {String redirectURL = locationHeader.getValue();System.out.println("==================以下为fitbit服务信息===============");System.out.println("重定向的路径:" + redirectURL);code=redirectURL.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_type=authorization_code&code="+code;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();Map<String,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.wangmingla.cn/news/61979.html

相关文章:

  • 提供网站制作公司哪家好嘉兴网站建设方案优化
  • 张云网站建设seo美式
  • 外贸怎么做公司网站北京最新疫情最新消息
  • 公众号网站选择宁波seo优化公司
  • 网站服务器在哪里新浪体育nba
  • 男女生做爰视频网站上海网络推广公司
  • 嘉兴网站建设正规公司站长工具seo查询
  • 企业新品做众筹的美国网站国内搜索引擎排名第一的是
  • 购物平台网站建设百度竞价开户3000
  • 怎么做二维码微信扫后直到网站百度竞价排名机制
  • 北京迎来疫情第一波冲击网站整体优化
  • 苏州晶体公司网站企业网站模板免费下载
  • 谁能给个网站谢谢西安百度seo推广
  • 网站访问pv量是指什么哪些平台可以发布软文
  • 建设网站需要学什么程序seo内部优化方案
  • 企业网站 哪个cms好百度指数是怎么计算的
  • 教育网网站建设规范百度seo关键词排名 s
  • WordPress站内链接设置怎么去做推广
  • 长沙域名注册公司吴中seo网站优化软件
  • 宝鸡企业网站制作广州市口碑seo推广
  • 给政府做网站的科技公司电商运营推广是做什么的
  • app下载安装官方网站外贸独立站建站
  • 爱尚网站建设网站营销推广
  • 海洋专业做网站百度网盘网页版
  • 东莞网络关键词排名seo平台是什么意思
  • 网站建设术语解释东莞新闻最新消息今天
  • 杭州视频网站建设青岛网络推广公司哪家好
  • 通州青岛网站建设关键词首页排名优化
  • 手机做兼职的网站设计安卓优化大师官网
  • 高校门户网站源码宁波seo基础入门