获取fitbit api用户信息

问题描述

我一直在尝试获取 fibit 用户数据,但我卡在了中间。 我会详细说明我的问题。

首先我得到了我的详细信息 OAuth 2.0 客户端 ID, 客户端机密,
重定向 URI:http://localhost:8043/login

当我的应用程序重定向到 fitbit url 时,用户可以成功获得授权、验证并重定向到我的应用程序重定向 uri,即 http://localhost:8043/login。

授权成功后我的网址如下所示:

http://localhost:8080/login#access_token={user_access_token}& user_id{user_id}&scope=heartrate+nutrition+location+profile+social+sleep+weight+activity+settings&token_type=Bearer&expires_in=604481

使用上述网址,我如何获取用户信息? 这是我的代码

@GetMapping(value="/login")
public String data1(HttpServletRequest request,@RequestParam(value="access_token",required=false) List<String> access_token,@RequestParam(value="user_id",required=false) List<String> user_id,@RequestParam(value="scope",required=false) List<String> scope,@RequestParam(value="token_type",required=false) List<String> token_type,@RequestParam(value="expires_in",required=false) List<String> expires_in           
        ) throws IOException {
    //System.out.println(usr);
    String url="https://api.fitbit.com/1/user/-/profile.json";
        String body= "#access_token="+access_token+"&"+
            "user_id="+user_id+"&scope=+heartrate+nutrition+location+profile+social+sleep+weight+activity+settings&token_type=Bearer&expires_in=604481";
        OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body1 = RequestBody.create(mediaType,body);
        
        Request request1 = new Request.Builder()
          .url(url)
          .post(body1)
          .addHeader("content-type","application/x-www-form-urlencoded")
          .addHeader("cache-control","no-cache")
          .build();
        Response response = client.newCall(request1).execute(); 
        
        return "got the data";
}

上面的代码是我尝试过的方式,但我无法成功,因为 url 有 # 参数,因此我可以访问 url 中的值。 有没有其他方法可以使用 springboot 解决我的问题?

如果可能,请提供使用 springboot 的示例代码

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)