Windy Community
    • Unread
    • Categories
    • Groups
    • Go to windy.com
    • Register
    • Login

    I'm new to api work, urgent help, is the api key or the url wrong?

    Windy API v4
    1
    1
    302
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ofis 2O
      Ofis 2 | Premium
      last edited by

      I want to print the weather of a certain place coming from windy in Winform using the paint forecast API, but I see that there is an error in the url or apikey (

      Cannot GET /api/point-forecast/v2
      ) I am sharing my code, urgent help. public partial class Frmsettings : Form
      {

          private Timer dataFetchTimer;
          private static readonly HttpClient client = new HttpClient();
      
          public Frmsettings()
          {
              InitializeComponent();
              // Timer ayarlarını yapıyoruz
              dataFetchTimer = new Timer();
              dataFetchTimer.Interval = 60000; // 60 saniyede bir veri çekme (1000ms * 60)
              dataFetchTimer.Tick += DataFetchTimer_Tick;  // Timer tetiklendiğinde bu fonksiyon çalışacak
              MessageBox.Show("Timer interval set to: " + dataFetchTimer.Interval);  // Interval'in doğru ayarlandığını kontrol edin
              dataFetchTimer.Start();  // Timer'ı başlat
      
          }
      
          // Timer her tetiklendiğinde API'den veri çekme
          private async void DataFetchTimer_Tick(object sender, EventArgs e)
          {
              MessageBox.Show("Timer Triggered!");  // Bu mesaj görünüyor mu?
              await FetchWeatherData();  // Veriyi çekme işlemini başlat
            
          }
      
          private async Task FetchWeatherData()
          {
              string apiKey = "HcuoyBroUc8HeHz4ITN64JgnTAgHSCbY";  // Windy API anahtarınız
              double latitude = 40.091;  // Enlem
              double longitude = 33.409;  // Boylam
      
              // API URL'sini yazdırma
              string url = $"https://api.windy.com/api/point-forecast/v2?lat={latitude}&lon={longitude}&model=gfs¶meters=wind&levels=1000,500,250&key={apiKey}";
      
              // Mesajları UI thread'de göstermek
              this.Invoke((MethodInvoker)delegate
              {
                  MessageBox.Show("API URL: " + url);  // URL'yi yazdırın
              });
      
              try
              {
                  // API'ye istek gönderme
                  HttpResponseMessage response = await client.GetAsync(url);
      
                  // Yanıtın durumu
                  if (!response.IsSuccessStatusCode)
                  {
                      this.Invoke((MethodInvoker)delegate
                      {
                          MessageBox.Show($"Error: {response.StatusCode} - {response.ReasonPhrase}");
                      });
                      return;
                  }
      
                  string responseBody = await response.Content.ReadAsStringAsync();
                  this.Invoke((MethodInvoker)delegate
                  {
                      MessageBox.Show("API Response Body: " + responseBody);  // Yanıtı yazdır
                  });
      
                  // JSON verisini işleme (örneğin, rüzgar hızı ve yönü)
                  var weatherData = JsonConvert.DeserializeObject(responseBody);
                  this.Invoke((MethodInvoker)delegate
                  {
                      MessageBox.Show($"Deserialized Data: {weatherData}");  // Deserialize edilmiş veriyi yazdır
                  });
      
                  if (weatherData != null && weatherData.wind != null && weatherData.wind.Length > 0)
                  {
                      this.Invoke((MethodInvoker)delegate
                      {
                          MessageBox.Show($"Wind Speed: {weatherData.wind[0].speed} m/s");
                          MessageBox.Show($"Wind Direction: {weatherData.wind[0].direction} degrees");
                      });
                  }
                  else
                  {
                      this.Invoke((MethodInvoker)delegate
                      {
                          MessageBox.Show("Wind data not available");
                      });
                  }
              }
              catch (HttpRequestException ex)
              {
                  this.Invoke((MethodInvoker)delegate
                  {
                      MessageBox.Show($"Error: {ex.Message}");
                  });
              }
          }
      
      
      
          // JSON cevabını işlemek için sınıf
          public class WeatherResponse
          {
              public WindData[] wind { get; set; }
          }
      
          public class WindData
          {
              public double speed { get; set; }
              public double direction { get; set; }
          }
      
      
          //Kalecik enlem boylam
          //40.080, 33.404
          private void Frmsettings_Load(object sender, EventArgs e)
          {
              // Bu mesajı görüp görmediğinizi kontrol etmek için kullanabilirsiniz
              MessageBox.Show("Form Loaded!");  // Bu mesajı görmelisiniz
              dataFetchTimer.Start();
          }
      
      1 Reply Last reply Reply Quote 0
      • idefix37I idefix37 marked this topic as a regular topic on
      • SutyS Suty moved this topic from Bug Reports on
      • First post
        Last post
      Windyty, S.E. - all rights reserved. Powered by excellent NodeBB
      NodeBB & contributors, OSM & contributors, HERE maps
      Terms of Use     Privacy Policy