I'm trying to fetch daily data from google fit api, but I don't understand what's wrong in my request. I'm trying to get daily step count but I still recive error 401. Here is all the code implemented and i'm just trying to log the response.
const [user, setUser] = useState({ haslogin: false, accessToken: "" });
function login(response) {
if (response.wc.access_token) {
setUser({
...response.profileObj,
haslogin: true,
accessToken: response.wc.access_token,
});
}
}
function logout(response) {
setUser({ haslogin: false, accessToken: "" });
}
function handleLoginFailure(response) {
alert("Failed to log in");
}
function handleLogoutFailure(response) {
alert("Failed to log out");
}
const handleData = () => {
Axios.post(
"https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate",
{
aggregateBy: [
{
dataTypeName: "com.google.step_count.delta",
dataSourceId:
"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps",
},
],
bucketByTime: { durationMillis: 86400000 },
startTimeMillis: 1438705622000,
endTimeMillis: 1439310422000,
},
{
params: {
key: API_KEY,
},
headers: {
Authorization: `Bearer ${user.accessToken}`,
Accept: "application/json",
},
}
)
.then((response) => {
console.log("res", response);
})
.catch((err) => console.log(err));
};
Can anyone help me with this issue?
Thanks