A
A
Alex Bragin2022-03-24 08:15:19
API
Alex Bragin, 2022-03-24 08:15:19

I have access to the sports statistics API, what should I do with it?

The bottom line:
For one project on wp, they gave access to the API (link and private key), BUT never had to work with the API before, I started to study the WP REST API https://developer.wordpress.org/rest-api/ (although everything is quite explained intelligibly), as a result, I got even more confused, as I understood (maybe I'm wrong) - this is about organizing access to your API, but how to pull data (a lot of statistics) from another site. I have been friends with the VP structure, hooks and everything (as it turned out, not everything) that I need in VP for a long time. The problem, it seems to me, is in the elementary (I'm probably already going in circles), but I can't catch up with how to adjust it for my task.

I would be grateful for any Examples, first of all, directly "ON THE FINGERS" (where to start and where to go), if you suddenly have a couple of screenshots, then it's generally wonderful, or advice on the case, but without trolling and show-off, like: "google help", "smoke mana", etc.

Given: normal shared hosting (access via ftp and through the panel to the database) + site on the vp (conditionally considered default) + access to the API => you need to display sports events statistics on an arbitrary page + accordingly, there should be an entry in the database = Game Over ! Ideally (this does not happen, of course, BUT at least dream up), someone can show the example of 2-3 screenshots that capture the file structure (with the file name) + lines. I understand that the time taken for this is just a waste of time for most of the gurus, unfortunately.

So far, from what I saw in the API thread, it does not particularly clarify the issue, there were examples with the output of store products, but this does not fit at all, although it works relatively easily - I repeated everything without difficulty, but in this case it is not applicable to the task.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HemulGM, 2022-03-24
@HemulGM

There is an endpoint - an address to the server, there are routes (or methods)
For example, the getCSGOStatistic method, which allows you to specify several parameters, count and offset. Those. how many elements to get and from which element in order
You just take and execute a GET request. Let's assume that your server with api will be here https://yourendpint.ru/api/v1/

https://yourendpint.ru/api/v1/getCSGOStatistic?count=100&offset=0

In response, you get a json object. What methods, what parameters they have, and what
answers, see the API documentation .
then the type of the variable of the last poll of the server with api and this will be done by the first one who opened your site, if the statistics have not been requested for a long time

A
Artem Zolin, 2022-03-25
@artzolin

I don't have your football statistics api, but I will give three working examples of using different apis WITHOUT using the WP REST API
YouTube Api

$args = [
  'part' => 'snippet', // какие параметры включить в ответ
  'q' => 'WordPress', // поисковый запрос
  'maxResults' => 50, // кол-во результатов в ответе
  'key' => 'xxx', // ключ
];

$api_url = add_query_arg( $args, 'https://www.googleapis.com/youtube/v3/search' ); 

$json_result = wp_remote_get( $api_url );

$body = json_decode( $json_result['body'] );
var_dump( $body );

Openweathermap API
$args = [
  'lat' => '43.671387', // широта
  'lon' => '40.297416', // долгота
  'appid' => 'xxx', // // ключ
  'lang' => 'ru', // язык
];

$api_url = add_query_arg( $args, 'https://api.openweathermap.org/data/2.5/weather' );

$json_result = wp_remote_get( $api_url );

$body = json_decode( $json_result['body'] );
var_dump( $body );

Kinopoiskapiun official API
$person_id = '967312'; // id персоны
$api_url = 'https://kinopoiskapiunofficial.tech/api/v1/staff/' . $person_id;

$args = array(
  'headers' => array(
    'X-API-KEY' => 'xxx', // ключ
    'Content-Type' => 'application/json',
  ),
);

$json_result = wp_remote_get( $api_url, $args );

$body = json_decode( $json_result['body'] );
var_dump( $body );

In the latter case, the key is not passed in the search bar, but in the headers, judging by the screenshots, this is your case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question