Site
Home / Forum / General Discussion / New on the site

New on the site


Posted: 08 Jan 2021 20:21
deleted user
Hi,
I am a new user on the site.
I am looking for a API to display some football infos (results, standing, live scores, stats..). I just saw your website.
I didn't saw anything about the cost of your API.
How much does your API cost ?
Is there some example of scripts ?
Thanks a lot
Webfoot

Posted: 08 Jan 2021 21:43

Ovokx
Posts: 1,697
Joined: 2020-06-17

Welcome aboard! Here you can find the info you are requesting

https://www.thesportsdb.com/api.php

Enjoy your stay and if you have any doubts, don't hesitate to ask us!

Posted: 08 Jan 2021 21:57
deleted user
Hi, Thanks for your answer.
Yes I read this page before to post on this forum.
Till now I used API with a cURL script (and a foreach loop).
To use of your, what we have to do ? We have to download PHP libraries ?
For example if I want to display automatically the last results of a championship ?
Thanks
PS : Seeably I posted two times the same topic. Is it possible to delete the other please ? I tried to do it by clicking on the recycle bin but no changes were made


Posted: 08 Jan 2021 22:17

zag
Posts: 3,327
Joined: 2020-03-23

Hi, Thanks for your answer.
Yes I read this page before to post on this forum.
Till now I used API with a cURL script (and a foreach loop).
To use of your, what we have to do ? We have to download PHP libraries ?
For example if I want to display automatically the last results of a championship ?
Thanks
PS : Seeably I posted two times the same topic. Is it possible to delete the other please ? I tried to do it by clicking on the recycle bin but no changes were made


Hi yes just sign up on patreon for a simple JSON api with livescore data with an API key. Saying that, a lot of our site is free to use for other data and will stay that way

You will need some kind of programming language such as PHP or Javasript to decode the data and display on a web page. You can use 6 or 7 lines of code to show it with standard PHP json_decode function or indeed CURL.

https://www.w3schools.com/php/func_json_decode.asp

If you want to use a seperate library (some people find that easier) There is a very nice PHP library coming along here from one of our users if you want something quick and simple:

https://github.com/nkl-kst/the-sports-db


Posted: 08 Jan 2021 22:23

zag
Posts: 3,327
Joined: 2020-03-23

If you want to test our API its very easy to in a browser.

Just copy and paste an API url into a web browser and it should show lots of data right away.

If you want to see the data in a structured way then install the json_view extension for google chrome.

https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh

Posted: 08 Jan 2021 22:36
deleted user
Yes i saw the php library (on this topic https://www.thesportsdb.com/forum_topic.php?t=5198) , i dowloaded it before to post on this forum.
I just try to learn how to display the datas (i am a beginner).
Till now i just used an API with a cURL (the script was given by the owner of the API and i just had the foreach loop to create, i didn't had any libraries to manage)

Posted: 08 Jan 2021 22:44

zag
Posts: 3,327
Joined: 2020-03-23

Yes i saw the php library (on this topic https://www.thesportsdb.com/forum_topic.php?t=5198) , i dowloaded it before to post on this forum.
I just try to learn how to display the datas (i am a beginner).
Till now i just used an API with a cURL (the script was given by the owner of the API and i just had the foreach loop to create, i didn't had any libraries to manage)


If you are a beginner then I would just do it the way you always have done, cURL should work fine and then just loop over the array. I suggest you look into some tutorials because with PHP it should be very easy:

1) Load the JSON URL into a file object
2) Decode JSON into an array
3) Var_dump the array to test your data
4) Once you understand the structure the loop over the data and print the results

Posted: 08 Jan 2021 22:49
deleted user
For example till now i used of this kind of script (provided by the creator of the api)



And after in the body, i made my foreach loops

Posted: 09 Jan 2021 10:44

zag
Posts: 3,327
Joined: 2020-03-23

For example till now i used of this kind of script (provided by the creator of the api)

https://zupimages.net/up/21/01/b2x3.png

And after in the body, i made my foreach loops


Yes thats pretty much perfect and how I do things when I need to send API keys in headers!



Posted: 09 Jan 2021 12:13
deleted user
So for example to get the last results of the French Ligue 1 for example (as I am for France), what URL i need to put in the curlopt url ?
It seem it works also without to put the headers


Posted: 09 Jan 2021 13:28

zag
Posts: 3,327
Joined: 2020-03-23

So for example to get the last results of the French Ligue 1 for example (as I am for France), what URL i need to put in the curlopt url ?
It seem it works also without to put the headers


https://www.thesportsdb.com/api/v1/json/1/eventspastleague.php?id=4334


All this info is on the API instruction page

Posted: 09 Jan 2021 14:03
deleted user
Thanks it seems ok
When i type the url in the curlopt_url i have this page


Posted: 09 Jan 2021 16:11
deleted user
I made my foreach loop, it seems working great ...
On the results, there is not the logo of each team in "detail" ?
For example i would like to do something like :



For the next events, is it possible to change the number of events ? (for example 10 instead of 15)

zag
Posted: 09 Jan 2021 18:44

zag
Posts: 3,327
Joined: 2020-03-23

So to lookup the team badges you would have to use the lookupteam API

https://www.thesportsdb.com/api/v1/json/1/lookupteam.php?id=133604

as a 2nd call using the Home and Away Team ID you have in the event details.

For the 10 events limit you could put a counter in the code and then break from the loop when it reaches 10 All should be quite simple with PHP.

Posted: 09 Jan 2021 19:40
deleted user
For the 10 events limit you could put a counter in the code and then break from the loop when it reaches 10

I tried to insert a for loop and in this for loop my foreach loop and i get 10 times the 15 matches (so 150 matches ).
I also tried with a while loop, it loops at the infinite on the 15 matches again
It would be great to have an option to choose the number of matches (for example i want 10 matchs cause it is the number of matches for each round in the french championship).

Posted: 10 Jan 2021 11:05
deleted user
Humm maybe I am wrong in my way to process
I use of this kind of script to display the datas
I define a $json on a files_get_contents and after I use a json_decode
Is it a good process ? is there a better one ?
(i am still on my problem to display logos and number of matches)

Thanks

Posted: 10 Jan 2021 13:38
deleted user
I finally succeeded to display 10 matches instead of 15...
but i have another question. It is possible to define automatically the last round ?
I used of these datas : https://www.thesportsdb.com/api/v1/json/1/eventsround.php?id=4334&r=19&s=2020-2021
the round is typed manually. Is there an option to define automatically the last one ?
Thanks

Posted: 10 Jan 2021 18:06
deleted user

So to lookup the team badges you would have to use the lookupteam API
https://www.thesportsdb.com/api/v1/json/1/lookupteam.php?id=133604
as a 2nd call using the Home and Away Team ID you have in the event details.


So each time we want to display a badge we need to use of the complete script for the json decode ?

Posted: 10 Jan 2021 20:40

zag
Posts: 3,327
Joined: 2020-03-23


So to lookup the team badges you would have to use the lookupteam API
https://www.thesportsdb.com/api/v1/json/1/lookupteam.php?id=133604
as a 2nd call using the Home and Away Team ID you have in the event details.


So each time we want to display a badge we need to use of the complete script for the json decode ?


Yes you would lookup each team individually and pull as a single variable the team badge.

There are many ways to improve this such as caching the badge locally and renaming it to the ID number.

Posted: 10 Jan 2021 23:19
deleted user

So to lookup the team badges you would have to use the lookupteam API
https://www.thesportsdb.com/api/v1/json/1/lookupteam.php?id=133604
as a 2nd call using the Home and Away Team ID you have in the event details.


So each time we want to display a badge we need to use of the complete script for the json decode ?

Yes you would lookup each team individually and pull as a single variable the team badge.

There are many ways to improve this such as caching the badge locally and renaming it to the ID number.


Seems difficult to realize ... it would be more simple to put each bagde on the page than the 2 badges on the same pic ...
It is possible to define automatically the last round ?
I used of these datas : https://www.thesportsdb.com/api/v1/json/1/eventsround.php?id=4334&r=19&s=2020-2021
the round is typed manually. Is there an option to define automatically the last one ?


Posted: 12 Jan 2021 21:39

zag
Posts: 3,327
Joined: 2020-03-23

No option for last round sorry.

For the badges you could do a very quick hack and download all the team badges, rename them to the idTeam number and put them on your web server. then just use PHP to display the badge like this

echo "img src='$team->idTeam'.png"

Posted: 12 Jan 2021 22:30
deleted user
For the last round i found another solution. I gave to the visitor a possibilty to choose the round he wants to see.
For the badges I'll see ...

Posted: 13 Jan 2021 11:39
deleted user
No option for last round sorry.

For the badges you could do a very quick hack and download all the team badges, rename them to the idTeam number and put them on your web server. then just use PHP to display the badge like this

echo "img src='$team->idTeam'.png"


I don't know how can I use a $team->idTeam'.png if the pics are on my server.
if i do a switch case condition on an external file and call it with an include on my page, I could work ?
In fact my problem for the badges is that the id of the team is specified in the url

Posted: 14 Jan 2021 23:28
deleted user
Hi,
I renamed the teams I want to use their french name. For that i made a simple php page with a switch case called in my code by an include
For the last events, no problems all teams are correctly displayed but for the next events, for the strAwayTeam, i have a "1" written beside the name of the team.
This "1" is not in my code (I checked several times)
I looked at the code generated in my console and I have a bis_skin_checked="1" .
I think it is coded in your API. How can I "uncheck" it ?
Thanks


Who is Online?

In total there are 68 users online :: 3 registered, 0 hidden and 65 guests (based on users active over the past 5 minutes) Most users ever online was 424 on Fri Nov 10, 2017 9:02 pm

About Us

Discussion forum for TheSportsDB.com site and related topics

Rules

- Be Polite
- Respect other users
- Always post log files with issues
- Try to be helpful
- No Piracy discussion

Showing 0 to 24 (Total: 24)