Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Can't get Google fit data in react app: error 400, 401

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!