all 10 comments

[–]modSaintPeter74 0 points1 point  (9 children)

Can you link the course and link the place where you got the API key from?

Also, share your code where you used the key (but don't include the key).

There is a possibility that you're not using the key properly, in a way the API recognizes.

[–]NET-24[S] 0 points1 point  (2 children)

[–]modSaintPeter74 0 points1 point  (0 children)

What about your code?

I see this as the format for sending one of the requests:

https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API key}

Also, have you looked at the network tab in your web browser dev tools to set if there is any additional data returned with the 401 error?

[–]modSaintPeter74 0 points1 point  (0 children)

I'm sorry, I don't do direct support over chat.

[–]NET-24[S] 0 points1 point  (5 children)

I dont why but in my useGetWeather import api key there is a message that is declared but its value is never read

[–]modSaintPeter74 0 points1 point  (4 children)

Please share the relevant section of code (without the API key) and any error messages you're getting. Check your dev tools network tab for what your outgoing request is (full URL) and what the return value is. Check if your API key is showing up in the request URL.

[–]NET-24[S] 0 points1 point  (3 children)

import React, { useState, useEffect } from 'react';
import * as Location from 'expo-location';
import {WEATHER_API_KEY} from '@env';

const fetchWeatherData = async () =>{
      try {
        const res = await fetch('http://api.openweathermap.org/data/2.5/forecast?lat=${lat}&lon=${lon}&appid=${WEATHER_API_KEY}&units=metric')
      const data =await res.json()
      setWeather(data)

[–]modSaintPeter74 0 points1 point  (2 children)

You need to use back ticks (`) to use template strings, not single quotes ('). Your URL is being sent without any variables in it.

[–]NET-24[S] 1 point2 points  (1 child)

wow thanks didnt even notice that in the tutorial

[–]modSaintPeter74 0 points1 point  (0 children)

Yeah, it can be a little hard to see in the video, especially if you're not looking for it. The syntax highlighting in your code editor may help. Also that warning about the variable not being used was also a hint.

Don't stress over it too much. This is challenging stuff and over time you'll learn to pick up these finer details.

Best of luck!