Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
How do i use an API on the P5js library?

I've been working on the p5js library and i'm trying to use an API to get access to weather data for my project, but the editor keeps throwing an error and I don't know why Here's my code:

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(){
}

Can someone help point out what's wrong with my code?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should post the errors you're getting. (Since you were already using the p5.js editor you could also share a link so it's easier to for everyone else to replicate your issue)

I've just tried your code in the p5 web editor and I'm getting this error in the browser's JS Console:

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.

Sometimes errors can be cryptic, but in this case it's pretty straight forward:

  • p5.js is loaded from an HTTPS domain (https://editor.p5js.org)
  • the weather API is accessed via HTTP(unsecure) (http://api.openweathermap.org/...etc.)
  • Ideally you'd load both via HTTPS (and the Weather API supports HTTPS).

This is makes the solution as simple as adding a single 's' :) (from http:// to https:// when accessing the Weather API)

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda