Спортрадар
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Получить список матчей английской Премьер-лиги.
/**
* @fileoverview Example of using Sportsradar API to get English Premier League
* soccer schedules, to use in adjusting campaigns.
* The principles of this example could easily be reused against any of the
* sports feeds available from Sportradar.
*
* Example: Get fixtures on 1st Oct 2016
* const schedule = getSoccerSchedule(2016, 10, 1);
*
* See https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#working_with_api_responses
* See http://developer.sportradar.us/
*/
// Replace with the API Key found on your Sportradar API Application page.
const API_KEY = 'ENTER_API_KEY';
// Insert your email address here for notification of API request failures.
const EMAIL_ADDRESS = 'ENTER_EMAIL_ADDRESS';
const VERSION = 2;
const LEAGUE = 'eu';
// Set to false when no longer in trial mode.
const TRIAL_MODE = true;
/**
* Retrieves a list of fixtures from the Soccer Schedule API.
* @param {number} year The year for which to get matches, in the form yyyy.
* @param {number} month The month for which to get matches, in range 1-12.
* @param {number} day The day for which to get matches, in range 1-31.
* @return {!Array.<!Object>} An array of object containing fixture info or
* null if the request was unsuccessful.
*/
function getSoccerSchedule(year, month, day) {
const urlTemplate =
'https://api.sportradar.us/soccer-%s%d/%s/matches/%d/%02d/%02d/schedule.xml?api_key=%s';
const accessLevel = TRIAL_MODE ? 't' : 'p';
const url = Utilities.formatString(
urlTemplate, accessLevel, VERSION, LEAGUE, year, month, day, API_KEY);
const response = UrlFetchApp.fetch(url);
return parseScheduleXml(response.getContentText());
}
/**
* Converts the date format returned from the XML feed into a Date object.
* @param {string} scheduleDate A date from the feed e.g. 2016-07-11T17:00:00Z
* @return {!Date} The resulting Date object.
*/
function parseScheduleDate(scheduleDate) {
return new Date(
scheduleDate.replace(/-/g, '/').replace('T', ' ').replace('Z', ' GMT'));
}
/**
* Parses the schedule XML, identifying only English Premier League Soccer
* matches, as an example of selecting events on which to make Google Ads
* changes.
* @param {string} xmlText XML response body from a call to the soccer schedule
* API.
* @return {!Array.<!Object>} An array of object containing fixture info.
*/
function parseScheduleXml(xmlText) {
const fixtures = [];
const scheduleElement = XmlService.parse(xmlText).getRootElement();
// The namespace is required for accessing child elements in the schema.
const namespace = scheduleElement.getNamespace();
const matchesElement = scheduleElement.getChild('matches', namespace);
const matchElements = matchesElement.getChildren();
for (let i = 0, matchElement; matchElement = matchElements[i]; i++) {
const status = matchElement.getAttribute('status').getValue();
const scheduled = matchElement.getAttribute('scheduled').getValue();
const scheduledDate = parseScheduleDate(scheduled);
const categoryElement = matchElement.getChild('category', namespace);
const country = categoryElement.getAttribute('country').getValue();
const tournamentElement = matchElement.getChild('tournament', namespace);
const tournamentName = tournamentElement.getAttribute('name').getValue();
if (tournamentName === 'Premier League' && country === 'England') {
const homeElement = matchElement.getChild('home', namespace);
const awayElement = matchElement.getChild('away', namespace);
const homeTeamName = homeElement.getAttribute('name').getValue();
const awayTeamName = awayElement.getAttribute('name').getValue();
fixtures.push({
date: scheduledDate,
homeTeam: homeTeamName,
awayTeam: awayTeamName
});
}
}
return fixtures;
}
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2024-09-12 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Отсутствует нужная мне информация"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Слишком сложен/слишком много шагов"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Устарел"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Проблема с переводом текста"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Проблемы образцов/кода"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Другое"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Прост для понимания"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Помог мне решить мою проблему"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Другое"
}]
{"lastModified": "\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435: 2024-09-12 UTC."}
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 2024-09-12 UTC."]]