Bruce Gust
asked on
How can I get these two "GETs" to play nicely?
I'm building a Fitbit API and we're going great guns but I've run into a snag and I'm confident it's due to my being new to Node.js.
This works:
...and this works:
Now, are you ready for this?
I've got to retrieve information that's coming from multiple endpoints. So, I tried to do this:
And I get this error:
.then(answers => {
^
SyntaxError: Unexpected token .
I'm assuming it's because I'm going about this the wrong way.
I need two sets of information, one from "client.get(activities)' and one from "client.get('activites/cal ories')."
How do I make that happen?
This works:
exports.getCallback = (req, res, next) => {
client.getAccessToken(req.query.code, 'http://localhost:3000/callback')
.then(result => {
// use the access token to fetch the user's profile information
//client.get("/profile.json", result.access_token)
client.get('/activities/date/2019-11-07.json', result.access_token)
.then(results => {
console.log(results[0].goals.calories);
//res.send(results[0]);
}).catch(err => {
const error = new Error(err);
error.httpStatusCode = 500;
return next(error);
});
});
};
...and this works:
exports.getCallback = (req, res, next) => {
client.getAccessToken(req.query.code, 'http://localhost:3000/callback')
.then(result => {
// use the access token to fetch the user's profile information
//client.get("/profile.json", result.access_token)
client.get("/activities/calories/date/today/1d.json", result.access_token)
.then(answers => {
.then(answers => {
res.send(answers[0]["activities-calories"][0].value);
}).catch(err => {
const error = new Error(err);
error.httpStatusCode = 500;
return next(error);
});
});
};
Now, are you ready for this?
I've got to retrieve information that's coming from multiple endpoints. So, I tried to do this:
exports.getCallback = (req, res, next) => {
client.getAccessToken(req.query.code, 'http://localhost:3000/callback')
.then(result => {
// use the access token to fetch the user's profile information
//client.get("/profile.json", result.access_token)
client.get('/activities/date/2019-11-07.json', result.access_token)
.then(results => {
console.log(results[0].goals.calories);
//res.send(results[0]);
}).catch(err => {
const error = new Error(err);
error.httpStatusCode = 500;
return next(error);
});
[b]client.get("/activities/calories/date/today/1d.json", result.access_token)
.then(answers => {
.then(answers => {
res.send(answers[0]["activities-calories"][0].value);
}).catch(err => {
const error = new Error(err);
error.httpStatusCode = 500;
return next(error);
});[/b]
});
};
And I get this error:
.then(answers => {
^
SyntaxError: Unexpected token .
I'm assuming it's because I'm going about this the wrong way.
I need two sets of information, one from "client.get(activities)' and one from "client.get('activites/cal
How do I make that happen?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Haha. I have no idea what that is, but thanks (I think!)
ASKER
This will do the trick! I wish you were local, I'd buy you a Chick Fil A Gift Card!