weixin_33691817 2018-05-11 03:38 采纳率: 0%
浏览 77

本地主机拒绝连接:

I am testing a Javascript/AJAX application that connects to FitBit API using Oauth 2.0 authentication to return heart rates, and print them on the console. The application was able to connect to Fitbit API and obtain an access token from teh Fitbit API. The problem is I am getting the error below every time I run the apps and it wont show the fitbit data on the console:

This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED**


I am running this application on Windows 10. My file structure is this:
C:\fitbit_javascript
Under the fitbit_javascript folder are two files: index.html amd app.js
Here are the codes:

index.html:
<!DOCTYPE html>
<html>
    <head>
        <title>Fitbit API JavaScript</title>
    </head>
        <body>
        <a href="https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=22CQ9N&redirect_uri=http%3A%2F%2Flocalhost%2Ffitbit_javascript%2F&scope=activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=604800">Login to Fitbit</a>

    <script src="app.js"></script>
    </body>
</html>

app.js:

// get the url
var url = window.location.href;

//getting the access token from url
var access_token = url.split("#")[1].split("=")[1].split("&")[0];

// get the userid
var userId = url.split("#")[1].split("=")[2].split("&")[0];

console.log(access_token);
console.log(userId);
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.fitbit.com/1/user/'+ userId 
+'/activities/heart/date/today/1w.json');
xhr.setRequestHeader("Authorization", 'Bearer ' + access_token);
xhr.onload = function() {
   if (xhr.status === 200) {
      console.log(xhr.responseText)
   }   
};
xhr.send();
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改