Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $access_token = '';
- function librus_login($username, $password)
- {
- global $access_token;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,"https://api.librus.pl/OAuth/Token");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- "username=$username&password=$password&grant_type=password");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/x-www-form-urlencoded',
- 'Cache-Control: no-cache',
- //'Authorization: Basic wmSyUMo8llDAs4y9tJVYY92oyZ6h4lAt7KCuy0Gv'
- 'Authorization: Basic MzU6NjM2YWI0MThjY2JlODgyYjE5YTMzZjU3N2U5NGNiNGY='
- //'Authorization: Basic Mjo1MmI2MmI4MjJkY2E1ZDQyODgxMTVhODNiOWM1ZDdjYw=='
- //'Authorization: Basic MC4wNjkyODcwMCAxNTI4NzAzMzEyXzZmZTljZjc1MDhjMzNkZThiNDYwMzQ0MDljYTY4NmNl'
- ));
- // in real life you should use something like:
- // curl_setopt($ch, CURLOPT_POSTFIELDS,
- // http_build_query(array('postvar1' => 'value1')));
- // receive server response ...
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $json = curl_exec ($ch);
- echo $json;
- curl_close ($ch);
- $result = json_decode($json, true);
- $access_token = $result['token_type'].' '.$result['access_token'];
- }
- function librus_get($url)
- {
- global $access_token;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Cache-Control: no-cache',
- 'Authorization: '.$access_token
- ));
- // in real life you should use something like:
- // curl_setopt($ch, CURLOPT_POSTFIELDS,
- // http_build_query(array('postvar1' => 'value1')));
- // receive server response ...
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $json = curl_exec ($ch);
- curl_close ($ch);
- $result = json_decode($json, true);
- return $result;
- }
- header('Content-Type: text/plain');
- librus_login('kuba.sz', 'haslo');
- echo $access_token;
- $grades = librus_get('https://api.librus.pl/2.0/Grades');
- var_dump($grades);
- foreach ($grades['Grades'] as $value) {
- echo $value['Grade'].' ';
- }
- $teachers = array();
- foreach (librus_get('https://api.librus.pl/2.0/Users/')['Users'] as $value) {
- $teachers[$value['Id']] = $value['FirstName'].' '.$value['LastName'];
- }
- var_dump($teachers);
- $subjects = array();
- foreach (librus_get('https://api.librus.pl/2.0/Subjects/')['Subjects'] as $value) {
- $subjects[$value['Id']] = $value['Name'];
- }
- var_dump($subjects);
- $grades_categories = array();
- foreach (librus_get('https://api.librus.pl/2.0/Grades/Categories/')['Categories'] as $value) {
- $grades_categories[$value['Id']] = $value['Name'];
- }
- var_dump($grades_categories);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement