我已经尝试了所有可能的方法从下面的microsoft health API网址获取正确的JSON响应。但它总是在JSON响应中给我“无效的授权请求”。我也尝试过Base64编码的授权令牌,但它没有响应。我不知道我哪里出错了?
String authToken="EwCgAvF0BAAUkWhN6f8bO0+g89MA1fmZueWyRkQAAfO43zeEeKVHsQJ5DiKwK62uBH2Xxh5mkV9t0EnExHELbz3u/qeS0uTqOUL4dyc3QwDikXQvNwFXWyK7sj6ChM3NrIF9L+7mI0ecmBme8IcghJ+kU+4SxHWZkOrshA8g5XW+KliOJbKvu4bus+JiMYxwKnqkLW6hkVxGQ1EHf0HzkHTNnWMbr1T4vNWJos7ITalOorV455MGekOvhEaFETrma9lQfos0RPRbDhdaKJiNFxUYQCvVywlbxRm96AOHlm/Be7GKYgF+vyktNs4dPgPz2l9MlzSGSE0IXtamSCiCaUocLDQ9yMY+jxKA4VPqhvbr1z3rc7fMk/wJvYebxVsDZgAACEzG05vV/JrAcAGHT5EeXaixNgTOW+S7CMcp3qpJtcl6MKveXA1e3fgvSQPCHnsy9nDoWYMgk4Uv6UkMbirkyzlG2JMFVpLg9PJE6sHIO0BZlkMb/DWMudrEsR3dwz00H/zAru9u6jMHnrbb44C/1z5lyXgwB3jItd/SWmRUdCBu3rF8IBXglAeyHxH+Mj5Zt2l+2rqly0p2sSqoUwgi49kThIggSlmod932fLWATHx5Lx3BN/wGfWU9XQplphPwYQvBsRnwv+gcZi9eK07aDIcdGhcp9J1fwCkjnBTZw+f0mDOyEfUSCyD0pnRXwz5CYDVN94TfFgZdnFAwi5wslKNUOYh6QBAJzaSXS/nj376FsORdEA1mUgowb/I2npitlr7+NTN6S+qWMdpEuiOVDVydi3L0H+xXKOaagzrels7bN7RpK0C+/kUqLfFrg8SeXxinqd+qhADu+56pRJnh8Sn3qdx/FmTQ/iGSYnrMMlT6SRDUjNVFoS3F540B";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("https://api.microsofthealth.net/v1/me/Summaries/Daily?startTime=" + startTime + "&endTime=" + endTime));
String authString = "Bearer " + authToken;
request.addHeader("Authorization", authString);
response = client.execute(request);
String json_string = EntityUtils.toString(response.getEntity());
答案 0 :(得分:0)
我认为您应该再次检查访问令牌以确保它有效。因为我在你的问题中使用了新的令牌,所以仍然是401。
GET https://api.microsofthealth.net/v1/me/Profile/
Authorization: bearer EwCgAvF0BAAUkWhN6f8bO0+g89MA1fmZueWyRkQAAfO43zeEeKVHsQJ5DiKwK62uBH2Xxh5mkV9t0EnExHELbz3u/qeS0uTqOUL4dyc3QwDikXQvNwFXWyK7sj6ChM3NrIF9L+7mI0ecmBme8IcghJ+kU+4SxHWZkOrshA8g5XW+KliOJbKvu4bus+JiMYxwKnqkLW6hkVxGQ1EHf0HzkHTNnWMbr1T4vNWJos7ITalOorV455MGekOvhEaFETrma9lQfos0RPRbDhdaKJiNFxUYQCvVywlbxRm96AOHlm/Be7GKYgF+vyktNs4dPgPz2l9MlzSGSE0IXtamSCiCaUocLDQ9yMY+jxKA4VPqhvbr1z3rc7fMk/wJvYebxVsDZgAACEzG05vV/JrAcAGHT5EeXaixNgTOW+S7CMcp3qpJtcl6MKveXA1e3fgvSQPCHnsy9nDoWYMgk4Uv6UkMbirkyzlG2JMFVpLg9PJE6sHIO0BZlkMb/DWMudrEsR3dwz00H/zAru9u6jMHnrbb44C/1z5lyXgwB3jItd/SWmRUdCBu3rF8IBXglAeyHxH+Mj5Zt2l+2rqly0p2sSqoUwgi49kThIggSlmod932fLWATHx5Lx3BN/wGfWU9XQplphPwYQvBsRnwv+gcZi9eK07aDIcdGhcp9J1fwCkjnBTZw+f0mDOyEfUSCyD0pnRXwz5CYDVN94TfFgZdnFAwi5wslKNUOYh6QBAJzaSXS/nj376FsORdEA1mUgowb/I2npitlr7+NTN6S+qWMdpEuiOVDVydi3L0H+xXKOaagzrels7bN7RpK0C+/kUqLfFrg8SeXxinqd+qhADu+56pRJnh8Sn3qdx/FmTQ/iGSYnrMMlT6SRDUjNVFoS3F540B
-- response --
401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/8.5
WWW-Authenticate: Bearer realm="mshealth" error="invalid_token"
X-AspNet-Version: 4.0.30319
AppEx-Activity-Id: 7c22cdab-5307-4b62-b81b-42e1315d9b1b
x-powered-by: ASP.NET
Date: Mon, 31 Aug 2015 07:04:00 GMT
Content-Length: 0