Spanish Problemas con app que no recibe respuesta de una API

Estoy desarrollando una app que mediante una API obtiene datos de unos partidos de fútbol en vivo, sin embargo, no recibo respuestas de _ResponseSuccess y _ResponseError ni en la lógica de programación ni en el Log. Probé la API en el sitio PostMan y funciona, pero acá no. Por favor me pueden indicar cual sería la causa, ya que he revisado información sobre HttpUtils y no veo cual es la falla.

El código en B4A:

Ejemplo:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private lblStatus As Label
    Private PanelScrollView As ScrollView
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("mainpage")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    GetLiveMatches
End Sub

Sub GetLiveMatches
    Dim job As HttpJob
    job.Initialize("LiveMatchesJob", Me)
    job.Download("https://v3.football.api-sports.io/fixtures?live=all")
    job.GetRequest.SetHeader("x-rapidapi-host", "v3.football.api-sports.io")
    job.GetRequest.SetHeader("x-rapidapi-key", "672239e740516f0166befb45b11da634")
    Log("Petición de partidos iniciada...")
    ' Muestra un mensaje de "Cargando..." en la UI
    ' Por ejemplo:
    lblStatus.Text = "Cargando partidos..."

End Sub

' Este sub se ejecutará cuando la petición termine
'Sub LiveMatchesJob_ResponseSuccess (joba As HttpJob)
Sub LiveMatchesJob_ResponseSuccess (job As HttpJob)
    Log("--> SUB LIVE_MATCHES_JOB_RESPONSESUCCESS FUE LLAMADA")
    ' Verifica si la petición fue exitosa
    If job.Success Then
        Log("Respuesta de la API recibida")
        
        Dim jsonResponse As String
        jsonResponse = job.GetString

        ' Ahora necesitas parsear este JSON
        ParseMatches(jsonResponse)
    Else
        ' Maneja el caso de error si la petición no fue exitosa
        Log("Error al obtener datos: " & job.ErrorMessage)
    End If

    ' Libera los recursos del objeto Job
    job.Release
End Sub

' Este sub se ejecutará si hay un error en la petición
'Sub LiveMatchesJob_ResponseError (joba As HttpJob, Reason As String, StatusCode As Int)
Sub LiveMatchesJob_ResponseError (job As HttpJob, Reason As String, StatusCode As Int)
    Log("Error en la petición: " & Reason)
    lblStatus.Text = "Error al cargar los datos: " & Reason
    job.Release
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
B4X:
Sub GetLiveMatches 
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://v3.football.api-sports.io/fixtures?live=all")
    j.GetRequest.SetHeader("x-rapidapi-host", "v3.football.api-sports.io")
    j.GetRequest.SetHeader("x-rapidapi-key", "672239e740516f0166befb45b11da634")
    Log("Petición de partidos iniciada...")
    ' Muestra un mensaje de "Cargando..." en la UI
    ' Por ejemplo:
    lblStatus.Text = "Cargando partidos..."
   
    Wait For (j) JobDone(j As HttpJob)
    ' Este sub se ejecutará cuando la petición termine
    Log("--> SUB LIVE_MATCHES_JOB_RESPONSESUCCESS FUE LLAMADA")
     ' Verifica si la petición fue exitosa
    
    If j.Success Then
        Log("Respuesta de la API recibida")
       Log(j.GetString)
      
        Dim jsonResponse As String
        jsonResponse = j.GetString

        ' Ahora necesitas parsear este JSON
        ParseMatches(jsonResponse)
    Else
        ' Maneja el caso de error si la petición no fue exitosa
        Log("Error al obtener datos: " & j.ErrorMessage)
        lblStatus.Text = "Error al cargar los datos: " & j.ErrorMessage
    End If
   
    ' Libera los recursos del objeto Job
    j.Release

End Sub




 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…