This is the request am making using the UA method of calling the V3 API, wrapped in a oath library for react. But it's getting deprecated starting June 2023 and I can't figure out how to recreate it in the GA4 v1 Beta API aka Google Analytics Data API. I have tried following Google's documentation but i just can't for my life understand how to make the request...
const login = useGoogleLogin({
onSuccess: async response => {
try {
console.log(response.access_token);
const res = await axios.get(`https://www.googleapis.com/analytics/v3/data/realtime?ids=ga:${gaID}&metrics=rt:activeUsers&access_token=${response.access_token}`, {
headers: {
"authorization": `Bearer ${response.access_token}`
}
})
if (res.data.rows == null) {
res.data.rows = 0
}
reponseGlobal = response
setactiveUsers(res.data.rows);
setloggedin(true);
const interval = setInterval(function() {
fetch ();
}, 5000);
} catch (err) {
console.log(err)
}
},
scope: 'https://www.googleapis.com/auth/analytics.readonly'
});