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

235
Views
¿Cómo uso una API en la biblioteca P5js?

He estado trabajando en la biblioteca p5js y estoy tratando de usar una API para obtener acceso a los datos meteorológicos para mi proyecto, pero el editor sigue arrojando un error y no sé por qué Aquí está mi código:

 function setup() { createCanvas(400,400); let url = 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric' loadJSON(url,gotData) } function gotData(data){ print(data); } function draw(){ }

¿Puede alguien ayudarme a señalar qué está mal con mi código?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Deberías publicar los errores que estás recibiendo. (Dado que ya estaba usando el editor p5.js, también podría compartir un enlace para que sea más fácil para todos replicar su problema)

Acabo de probar su código en el editor web p5 y recibo este error en la consola JS del navegador:

 p5.js:84555 Mixed Content: The page at 'https://editor.p5js.org/' was loaded over HTTPS, but requested an insecure resource 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric'. This request has been blocked; the content must be served over HTTPS.

A veces, los errores pueden ser crípticos, pero en este caso es bastante sencillo:

  • p5.js se carga desde un dominio HTTPS ( https://editor.p5js.org )
  • Se accede a la API meteorológica a través de HTTP (no seguro) ( http://api.openweathermap.org/...etc. )
  • Idealmente, cargaría ambos a través de HTTPS (y Weather API es compatible con HTTPS).

Esto hace que la solución sea tan simple como agregar una sola 's' :) (de http:// a https:// al acceder a la API de Weather)

 function setup() { createCanvas(400,400); let url = 'https://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric' loadJSON(url,gotData) } function gotData(data){ print(data); } function draw(){ }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
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!