Zugriff auf API schlägt fehl

  • VB.NET
  • .NET (FX) 4.0

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von s6fregne.

    Zugriff auf API schlägt fehl

    Huhu,
    ich möchte auf die API von fortnitetracker.com zugreifen. Laut der Seite kann ich darauf zugreifen, indem ich zum folgenden GET-Request einen API-Key im Header angebe. Nun ist mir nicht wirklich klar wie ich das Ganze machen sollte. Mein Versuch ist folgender:

    VB.NET-Quellcode

    1. Dim uri As New Uri("https://api.fortnitetracker.com/v1/profile/{pc}/{Benutzername}")
    2. If (uri.Scheme = Uri.UriSchemeHttp) Then
    3. Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
    4. request.Method = WebRequestMethods.Http.Get
    5. request.Headers.Add(HttpRequestHeader.Authorization, "Hier habe ich meinen API-Key angegeben")
    6. Dim response As HttpWebResponse = request.GetResponse()
    7. Dim reader As New IO.StreamReader(response.GetResponseStream())
    8. Dim tmp As String = reader.ReadToEnd()
    9. response.Close()
    10. MsgBox(tmp)


    Bei dem Versuch wurde keine Box mit Text angezeigt. Anstatt

    VB.NET-Quellcode

    1. request.Headers.Add
    habe ich es auch mit

    VB.NET-Quellcode

    1. request.Headers.Set
    versucht. Gleiches Ergebnis.

    Weiß jemand was ich falsch mache?


    Liebe Grüße
    Hallo

    s6fregne schrieb:

    Bei dem Versuch wurde keine Box mit Text angezeigt

    Das ist keine Fehlerbeschreibung. Läuft VS in eine Exception? Oder zeigst du uns nicht den ganzen Code?
    Ich kann es nicht probieren, mach mir jetzt sicher keinen Account dort.

    Grüße
    Sascha
    If _work = worktype.hard Then Me.Drink(Coffee)
    Seht euch auch meine Tutorialreihe <WPF Lernen/> an oder abonniert meinen YouTube Kanal.

    ## Bitte markiere einen Thread als "Erledigt" wenn deine Frage beantwortet wurde. ##

    Also, da man gar keine gültige Mailadresse angeben muss, habe ich jetzt doch ein Konto *gg*

    Klappt bei mir wunderbar:
    Anfrage: api.fortnitetracker.com/v1/profile/pc/Drusty
    Response:
    Spoiler anzeigen
    HTTP/1.1 200 OK
    Date: Tue, 02 Jan 2018 07:16:57 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 14476
    Connection: keep-alive
    Set-Cookie: __cfduid=daf94ab10f13e0d8bc83fcf788b546c191514877416; expires=Wed, 02-Jan-19 07:16:56 GMT; path=/; domain=.fortnitetracker.com; HttpOnly
    X-RateLimit-Limit-minute: 30
    X-RateLimit-Remaining-minute: 28
    Cache-Control: private
    Set-Cookie: ASP.NET_SessionId=1rgv0gztrw2ex2etahxcd4vh; path=/; HttpOnly
    Set-Cookie: UserName=Guest288; expires=Tue, 02-Jan-2018 07:32:11 GMT; path=/
    X-AspNetMvc-Version: 4.0
    X-AspNet-Version: 4.0.30319
    Set-Cookie: __ControllerTempData=AAEAAAD/////AQAAAAAAAAAEAQAAAOIBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuRGljdGlvbmFyeWAyW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldLFtTeXN0ZW0uT2JqZWN0LCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQMAAAAHVmVyc2lvbghDb21wYXJlcghIYXNoU2l6ZQADAAgWU3lzdGVtLk9yZGluYWxDb21wYXJlcggAAAAACQIAAAAAAAAABAIAAAAWU3lzdGVtLk9yZGluYWxDb21wYXJlcgEAAAALX2lnbm9yZUNhc2UAAQEL; path=/; HttpOnly
    X-Powered-By: ASP.NET
    X-Kong-Upstream-Latency: 175
    X-Kong-Proxy-Latency: 0
    Via: kong/0.11.0
    Server: cloudflare
    CF-RAY: 3d6bef8f6e538c82-VIE

    {
    "accountId": "2d1d20e2-b18d-4dac-98a9-8eb474dea404",
    "platformId": 3,
    "platformName": "pc",
    "platformNameLong": "PC",
    "epicUserHandle": "Drusty",
    "stats": {
    "p2": {
    "score": {
    "label": "Score",
    "field": "Score",
    "category": "General",
    "valueInt": 10276,
    "value": "10276",
    "rank": 102927,
    "percentile": 46.0,
    "displayValue": "10,276"
    },
    "top1": {
    "label": "Wins",
    "field": "Top1",
    "category": "Tops",
    "valueInt": 10,
    "value": "10",
    "rank": 31543,
    "percentile": 25.0,
    "displayValue": "10"
    },
    "top3": {
    "label": "Top 3",
    "field": "Top3",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top5": {
    "label": "Top 5",
    "field": "Top5",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top6": {
    "label": "Top 6",
    "field": "Top6",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top10": {
    "label": "Top 10",
    "field": "Top10",
    "category": "Tops",
    "valueInt": 35,
    "value": "35",
    "rank": 54695,
    "percentile": 7.0,
    "displayValue": "35"
    },
    "top12": {
    "label": "Top 12",
    "field": "Top12",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top25": {
    "label": "Top 25",
    "field": "Top25",
    "category": "Tops",
    "valueInt": 49,
    "value": "49",
    "rank": 84231,
    "percentile": 11.0,
    "displayValue": "49"
    },
    "kd": {
    "label": "K/d",
    "field": "KD",
    "category": "General",
    "valueDec": 2.63,
    "value": "2.63",
    "rank": 33153,
    "percentile": 12.0,
    "displayValue": "2.63"
    },
    "winRatio": {
    "label": "Win %",
    "field": "WinRatio",
    "category": "General",
    "valueDec": 9.3,
    "value": "9.3",
    "rank": 17608,
    "percentile": 13.0,
    "displayValue": "9.30"
    },
    "matches": {
    "label": "Matches",
    "field": "Matches",
    "category": "General",
    "valueInt": 107,
    "value": "107",
    "rank": 116798,
    "percentile": 49.0,
    "displayValue": "107"
    },
    "kills": {
    "label": "Kills",
    "field": "Kills",
    "category": "General",
    "valueInt": 255,
    "value": "255",
    "rank": 75361,
    "percentile": 31.0,
    "displayValue": "255"
    },
    "minutesPlayed": {
    "label": "Time Played",
    "field": "MinutesPlayed",
    "category": "General",
    "valueInt": 1101,
    "value": "1101",
    "rank": 86624,
    "percentile": 40.0,
    "displayValue": "18h 21m "
    },
    "kpm": {
    "label": "Kills Per Min",
    "field": "KPM",
    "category": "General",
    "valueDec": 0.23,
    "value": "0.23",
    "rank": 94935,
    "percentile": 27.0,
    "displayValue": "0.23"
    },
    "kpg": {
    "label": "Kills Per Match",
    "field": "KPG",
    "category": "General",
    "valueDec": 2.38,
    "value": "2.38",
    "rank": 37258,
    "displayValue": "2.38"
    },
    "avgTimePlayed": {
    "label": "Avg Match Time",
    "field": "AvgTimePlayed",
    "category": "General",
    "valueDec": 617.38,
    "value": "617.38",
    "rank": 23092,
    "percentile": 10.0,
    "displayValue": "10m 17s"
    },
    "scorePerMatch": {
    "label": "Score per Match",
    "field": "ScorePerMatch",
    "category": "General",
    "valueDec": 96.04,
    "value": "96.04",
    "rank": 118866,
    "percentile": 49.0,
    "displayValue": "96.04"
    },
    "scorePerMin": {
    "label": "Score per Minute",
    "field": "ScorePerMin",
    "category": "General",
    "valueDec": 9.33,
    "value": "9.33",
    "rank": 173854,
    "percentile": 65.0,
    "displayValue": "9.33"
    }
    },
    "p10": {
    "score": {
    "label": "Score",
    "field": "Score",
    "category": "General",
    "valueInt": 5479,
    "value": "5479",
    "rank": 161791,
    "percentile": 60.0,
    "displayValue": "5,479"
    },
    "top1": {
    "label": "Wins",
    "field": "Top1",
    "category": "Tops",
    "valueInt": 11,
    "value": "11",
    "rank": 52228,
    "percentile": 23.0,
    "displayValue": "11"
    },
    "top3": {
    "label": "Top 3",
    "field": "Top3",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top5": {
    "label": "Top 5",
    "field": "Top5",
    "category": "Tops",
    "valueInt": 24,
    "value": "24",
    "rank": 84746,
    "percentile": 11.0,
    "displayValue": "24"
    },
    "top6": {
    "label": "Top 6",
    "field": "Top6",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top10": {
    "label": "Top 10",
    "field": "Top10",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top12": {
    "label": "Top 12",
    "field": "Top12",
    "category": "Tops",
    "valueInt": 34,
    "value": "34",
    "rank": 116405,
    "percentile": 15.0,
    "displayValue": "34"
    },
    "top25": {
    "label": "Top 25",
    "field": "Top25",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "kd": {
    "label": "K/d",
    "field": "KD",
    "category": "General",
    "valueDec": 3.11,
    "value": "3.11",
    "rank": 16794,
    "percentile": 7.0,
    "displayValue": "3.11"
    },
    "winRatio": {
    "label": "Win %",
    "field": "WinRatio",
    "category": "General",
    "valueDec": 16.7,
    "value": "16.7",
    "rank": 7700,
    "percentile": 3.9,
    "displayValue": "16.70"
    },
    "matches": {
    "label": "Matches",
    "field": "Matches",
    "category": "General",
    "valueInt": 66,
    "value": "66",
    "rank": 164546,
    "percentile": 62.0,
    "displayValue": "66"
    },
    "kills": {
    "label": "Kills",
    "field": "Kills",
    "category": "General",
    "valueInt": 171,
    "value": "171",
    "rank": 106260,
    "percentile": 41.0,
    "displayValue": "171"
    },
    "minutesPlayed": {
    "label": "Time Played",
    "field": "MinutesPlayed",
    "category": "General",
    "valueInt": 799,
    "value": "799",
    "rank": 128428,
    "percentile": 48.0,
    "displayValue": "13h 19m "
    },
    "kpm": {
    "label": "Kills Per Min",
    "field": "KPM",
    "category": "General",
    "valueDec": 0.21,
    "value": "0.21",
    "rank": 81377,
    "percentile": 33.0,
    "displayValue": "0.21"
    },
    "kpg": {
    "label": "Kills Per Match",
    "field": "KPG",
    "category": "General",
    "valueDec": 2.59,
    "value": "2.59",
    "rank": 21685,
    "displayValue": "2.59"
    },
    "avgTimePlayed": {
    "label": "Avg Match Time",
    "field": "AvgTimePlayed",
    "category": "General",
    "valueDec": 726.36,
    "value": "726.36",
    "rank": 4445,
    "percentile": 2.5,
    "displayValue": "12m 6s"
    },
    "scorePerMatch": {
    "label": "Score per Match",
    "field": "ScorePerMatch",
    "category": "General",
    "valueDec": 83.02,
    "value": "83.02",
    "rank": 148892,
    "percentile": 56.0,
    "displayValue": "83.02"
    },
    "scorePerMin": {
    "label": "Score per Minute",
    "field": "ScorePerMin",
    "category": "General",
    "valueDec": 6.86,
    "value": "6.86",
    "rank": 197510,
    "percentile": 74.0,
    "displayValue": "6.86"
    }
    },
    "p9": {
    "score": {
    "label": "Score",
    "field": "Score",
    "category": "General",
    "valueInt": 445053,
    "value": "445053",
    "rank": 103,
    "percentile": 0.1,
    "displayValue": "445,053"
    },
    "top1": {
    "label": "Wins",
    "field": "Top1",
    "category": "Tops",
    "valueInt": 696,
    "value": "696",
    "rank": 42,
    "percentile": 0.1,
    "displayValue": "696"
    },
    "top3": {
    "label": "Top 3",
    "field": "Top3",
    "category": "Tops",
    "valueInt": 1025,
    "value": "1025",
    "rank": 25,
    "percentile": 0.1,
    "displayValue": "1,025"
    },
    "top5": {
    "label": "Top 5",
    "field": "Top5",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top6": {
    "label": "Top 6",
    "field": "Top6",
    "category": "Tops",
    "valueInt": 1201,
    "value": "1201",
    "rank": 33,
    "percentile": 0.1,
    "displayValue": "1,201"
    },
    "top10": {
    "label": "Top 10",
    "field": "Top10",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top12": {
    "label": "Top 12",
    "field": "Top12",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "top25": {
    "label": "Top 25",
    "field": "Top25",
    "category": "Tops",
    "valueInt": 0,
    "value": "0",
    "rank": 1,
    "displayValue": "0"
    },
    "kd": {
    "label": "K/d",
    "field": "KD",
    "category": "General",
    "valueDec": 5.33,
    "value": "5.33",
    "rank": 2630,
    "percentile": 1.0,
    "displayValue": "5.33"
    },
    "winRatio": {
    "label": "Win %",
    "field": "WinRatio",
    "category": "General",
    "valueDec": 36.0,
    "value": "36",
    "rank": 1387,
    "percentile": 0.4,
    "displayValue": "36.00"
    },
    "matches": {
    "label": "Matches",
    "field": "Matches",
    "category": "General",
    "valueInt": 1936,
    "value": "1936",
    "rank": 341,
    "percentile": 0.1,
    "displayValue": "1,936"
    },
    "kills": {
    "label": "Kills",
    "field": "Kills",
    "category": "General",
    "valueInt": 6613,
    "value": "6613",
    "rank": 158,
    "percentile": 0.1,
    "displayValue": "6,613"
    },
    "minutesPlayed": {
    "label": "Time Played",
    "field": "MinutesPlayed",
    "category": "General",
    "valueInt": 26326,
    "value": "26326",
    "rank": 63,
    "percentile": 0.1,
    "displayValue": "18d 6h 46m "
    },
    "kpm": {
    "label": "Kills Per Min",
    "field": "KPM",
    "category": "General",
    "valueDec": 0.25,
    "value": "0.25",
    "rank": 40325,
    "percentile": 22.0,
    "displayValue": "0.25"
    },
    "kpg": {
    "label": "Kills Per Match",
    "field": "KPG",
    "category": "General",
    "valueDec": 3.42,
    "value": "3.42",
    "rank": 6499,
    "displayValue": "3.42"
    },
    "avgTimePlayed": {
    "label": "Avg Match Time",
    "field": "AvgTimePlayed",
    "category": "General",
    "valueDec": 815.89,
    "value": "815.89",
    "rank": 2536,
    "percentile": 1.0,
    "displayValue": "13m 35s"
    },
    "scorePerMatch": {
    "label": "Score per Match",
    "field": "ScorePerMatch",
    "category": "General",
    "valueDec": 229.88,
    "value": "229.88",
    "rank": 28115,
    "percentile": 7.0,
    "displayValue": "229.88"
    },
    "scorePerMin": {
    "label": "Score per Minute",
    "field": "ScorePerMin",
    "category": "General",
    "valueDec": 16.91,
    "value": "16.91",
    "rank": 117435,
    "percentile": 40.0,
    "displayValue": "16.91"
    }
    }
    },
    "lifeTimeStats": [
    {
    "key": "Top 3",
    "value": "35"
    },
    {
    "key": "Top 5s",
    "value": "24"
    },
    {
    "key": "Top 3s",
    "value": "1025"
    },
    {
    "key": "Top 6s",
    "value": "1201"
    },
    {
    "key": "Top 12s",
    "value": "34"
    },
    {
    "key": "Top 25s",
    "value": "49"
    },
    {
    "key": "Score",
    "value": "460,808"
    },
    {
    "key": "Matches Played",
    "value": "2109"
    },
    {
    "key": "Wins",
    "value": "717"
    },
    {
    "key": "Win%",
    "value": "34%"
    },
    {
    "key": "Kills",
    "value": "7039"
    },
    {
    "key": "K/d",
    "value": "5.06"
    },
    {
    "key": "Kills Per Min",
    "value": "0.2"
    },
    {
    "key": "Time Played",
    "value": "19d 14h 26m "
    },
    {
    "key": "Avg Survival Time",
    "value": "13m 23s"
    }
    ]
    }

    Wichtig ist hald der Header. Hier mein Header: GET https://api.fortnitetracker.com/v1/profile/pc/Drusty HTTP/1.1 User-Agent: Fiddler TRN-API-KEY: <DEIN-API-KEY> Host: api.fortnitetracker.com

    Grüße
    Sascha
    If _work = worktype.hard Then Me.Drink(Coffee)
    Seht euch auch meine Tutorialreihe <WPF Lernen/> an oder abonniert meinen YouTube Kanal.

    ## Bitte markiere einen Thread als "Erledigt" wenn deine Frage beantwortet wurde. ##

    Hallo und danke für eure Antworten.

    Die Lösung mit der Angabe von
    ​TRN-Api-Key
    habe ich auch gefunden gehabt und hat das Problem wohl auch zur Hälfte mitgelöst.
    Meine Fehler habe ich gefunden:

    VB.NET-Quellcode

    1. ​Dim uri As New Uri("https://api.fortnitetracker.com/v1/profile/{pc}/{Benutzername}")


    Hier habe ich die geschweiften Klammern nicht entfernt.

    VB.NET-Quellcode

    1. ​If (uri.Scheme = Uri.UriSchemeHttp) Then


    Ebenfalls war die URL nicht korrekt für das Uri-Scheme, was bei diesem Vergleich geprüft wird. Ich hatte, wie oben zu sehen, https anstatt http in der URL angegeben.

    Kaum waren diese zwei Fehler behoben, hat auch alles wie gewünscht funktioniert. Was ich darauf gelernt habe: Code niemals mitten in der Nacht, wenn die Müdigkeit bereits sehr groß ist.

    Danke für jegliche Hilfe! :)