skip to Main Content

IONIC CAPACITOR AND REACT FOR NATIVE AND WEB APPS

When I m fetching photo data from google api with that code below. It works good but when i inspect on website i can see on photo src my APIKEY how can i solve that or what i should do ?

const fetchPhoto = async () => {
    if (photoName) {
      try {
        const maxHeightPx = 500;
        const maxWidthPx = 500;

        const url = `https://places.googleapis.com/v1/${photoName}/media?key=${GOOGLE_PLACES_API_KEY}&maxHeightPx=${maxHeightPx}&maxWidthPx=${maxWidthPx}`;
        const response = await CapacitorHttp.post({ url });
        setPhoto(response.url);
        setLoading(false);
      } catch (error) {
        setPhoto(images.thumbnail);
        setLoading(false);
        console.error("Error while fetching photo:", error);
      }
    }
  };

I dont know what to do

2

Answers


  1. Chosen as BEST ANSWER

    Okey guys. I solved that problem. I just need to change POST method to GET method. Then I got good results.


    1. You should NOT be calling the api in your code like that.
    2. Use example setup provided by google!
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search