Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/api/demo/ApiTest.php
<?php

// below php modules comes from Wiatrogon'a php-allegro-res-api
// https://github.com/Wiatrogon/php-allegro-rest-api
// It were commented and slightly changed ( parameters for get() function )
// by me. But all the code is from and 99,9% of glory shoud go to Wiatrogon.

require_once 'Resource.php';	//classes  
require_once 'Commands.php';	//classes
require_once 'Api.php';		//classes
require_once 'api_login0.php';	//login and allegro conection tokens

$current = file_get_contents($file);

$accessToken = file_get_contents('accessToken0'); 
$refreshToken= file_get_contents('refreshToken0');

//echo '$accessToken='.$accessToken.'<br><br>$refreshToken='.$refreshToken;
                                                                                             
$api = new Api($clientId, $clientSecret, $apiKey, $redirectUri.'/api/demo/ApiTest.php', $accessToken, $refreshToken);
//  the 4-th parameter should point to Your auth file.php - in this example - this file.
//  on my server it's located in http://myserver.com/api/demo/ directory
//  and during the regirtration process I put [ http://myserver.com ] as a url.
//  if You put in smoewhere different directory You  shold edit added string
//  '/api/dem/ApiTest.php'  



/* new token    */      
$code = $_GET['code'];
//  parameter needed for authorisation - returned by Allegro while two-phase auth method

if(strlen($code)<3)
{  // run once - for authorization code passing to allegro
  $authUri=$api->getAuthorizationUri();

//echo $authUri."<br><br><br>"; 
//  IMPORTANT!!!!!
//  You may have to run it once manually - uncoment the above line, copy from browser output
//  paste & execute in browser being Loged in to allegro. It asks ( allegro web page ) You
//  if You agree to run program named [ name_given_while_registration_process ]. You should
//  probably agree  ;-)

  header("Location: $authUri");
  exit;
}
$tokenn = $api->getNewAccessToken($code);
$tokenn=json_decode($tokenn,true);

$file = 'accessToken0';    
$file2 = 'refreshToken0';
$current = $tokenn['access_token'];  
$current2 = $tokenn['refresh_token'];
if($current=='' and !$accessToken=='')  file_put_contents('last_accessToken0', Date('Y-m-d H:i:s')); 
file_put_contents($file, $current);    
file_put_contents($file2, $current2);
                           
          
/* reresh token                            
$tokenn = $api->refreshAccessToken();
$tokenn=json_decode($tokenn,true);

$file = 'accessToken0';    
$file2 = 'refreshToken0';
$current = $tokenn['access_token'];  
$current2 = $tokenn['refresh_token'];
file_put_contents($file, $current);    
file_put_contents($file2, $current2);
                    
//c6c0a263-35fe-11ea-a53e-db43676583b3   
$data = '{
    "waybill": "123",
    "carrierId": "INPOST",
    "carrierName": null,
    "lineItems": [
        {
        "id": "c6c0a261-35fe-11ea-a53e-db43676583b3"
        }
    ]
}';    */            

echo '<pre>';
//$api->order('checkout-forms/c6c0a263-35fe-11ea-a53e-db43676583b3')->shipments($data)->post();
$response=$api->order('events?limit=1&from=1578917920213991')->get();
$response=json_decode($response,true);
echo print_r($response,true);
echo '</pre>';
// PUT https://allegroapi.io/offers/12345/change-price-commands/84c16171-233a-42de-8115-1f1235c8bc0f
//$api->offers(12345)->commands()->change_price($data);
     
     /*                                      
$response=$api->order('events?limit=1&from=1578917920213991')->get();


$response=json_decode($response,true);
echo "<br>[============ All the items selected and get from the server - OUR MAIN GOAL!! ==================]<br><pre>";
echo print_r($response,true);

echo "</pre><br><br><br>";
       */
       
 
//  the 4-th parameter should point to Your auth file.php - in this example - this file.
//  on my server it's located in http://myserver.com/api/demo/ directory
//  and during the regirtration process I put [ http://myserver.com ] as a url.
//  if You put in smoewhere different directory You  shold edit added string
//  '/api/dem/ApiTest.php'  
          
                 


?>