Next.js Discord

Discord Forum

Implementing Google Reviews in Nextjs 13

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Avatar
Asiatic LionOP
Hey there 🙂

I managed to implement google reviews using the places API, but unfortunately this is a bit limited, as it seems I can only get 5 reviews of one location, and if I ever where to use this component for a website/customer with more than one location, I would be a bit in a mess...

So my idea is to use the My Business API and that's where the trouble really begins: I have no idea how to implement an OAuth 2.0 flow on a website without user-interaction...

Can anyone help me with this?

2 Replies

Avatar
Asiatic LionOP
That's my current function:async function fetchReviews(): Promise<PlaceData> { const placeId = process.env.PLACE_ID; const apiKey = process.env.GOOGLE_PLACES_KEY; try { const response = await fetch(https://maps.googleapis.com/maps/api/place/details/json?place_id=${placeId}&fields=review,url,rating&key=${apiKey}&reviews_no_translations=true&reviews_sort=newest`,);
const data = await response.json();
if (!response.ok) {
throw new Error('Failed to fetch');
}
console.log(data)
const res = data.result ? data.result.reviews : [];
//const url = data.result ? data.result.url : "";

const rating = data.result ? data.result.rating : 0;
const reviews = res.map((review: any) => {
return {
author: review.author_name,
link: url,
rating: review.rating,
text: review.text
}
});
return {rating, reviews};
} catch (e) {
console.error(e);
return {rating: 0, reviews: []};
}
}`
Avatar
i am not clear what the problem you face. Now you are going to use your own API key instead of Google provider tokens of users.
so why do you still need OAuth, which allows you to get user's tokens via Google Auth provider?