Please life savers, am having issues with a php file on my website file that needed to use composer and packaglist to include or autoload the file, am kind of new to use of composer and i need your help.
Below is the code.
// Loading Requests
require_once 'path/requests/library/Requests.php';
// Registering an autoloader
Requests::register_autoloader();
// Preparing the request message
$url = 'https://test.api.amadeus.com/v1/security/oauth2/token';
$auth_data = array(
'client_id' => 'QF1Z4rlmy-clientid-pleasecloseyoureyesIc8Z',
'client_secret' => 'MysecretGsfZE6j-dontlookhgf',
'grant_type' => 'client_credentials'
);
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
try {
// Sending the request message by POST
$requests_response = Requests::post($url, $headers, $auth_data);
// Server returns a Requests_Response object
echo 'Response from the authorization server:';
$response_body = json_decode($requests_response->body);
echo '<pre>', json_encode($response_body, JSON_PRETTY_PRINT), '</pre>';
if(property_exists($response_body, 'error')) die;
// Extract and store the access token
$access_token = $response_body->access_token;
} catch (Exception $e) {
print_r($e->getMessage());
}
Am having a problem passing the require_once path, i know the is a link to a vendor dependency usin compozer but all the tutorials i watched
is just about installing compozer on your machine, but i just need to upload this file in my webhost, any host shared website host.
so i dont understand why i need to install composer first on my machine before using the file.
i wanted is to get this working in my website files as a normal PHP file should so that i can access the token and get response back.
Am testing the script on my XAMPP local server.
Please any guide or help is much appreciated in advance.
your PHP app must have the capability to implement HTTP requests . You could write the code to add that capability to your PHP app, but it makes more sense to use the Requests package, which provides useful helper functions.
To download and install Requests, you can use Composer, a PHP dependency-management tool that lets you declare the libraries your project depends on.
so i want to possibly know either of these two things or at best know all the two of them for future projects
how to make use of the Composer they talked about in my website files to autoload php files throughout my website.
How to write my own code to make HTTP request without the need for any dependencies or library
nop i did not, i dont even know how to go about the installation, and secondly do i really need it installed? since all am building is a website folder full of php files and html that i will upload to my webhost server, is not meant for my local machine, just test running with xampp and MAMP
What came to my mind was using the method we all use for javascript src method to enable jquery. Like i should download the full folder called composer with its subfolders called vendor and then download any of the Request package and put it inside the vendor folder and then use this code in any of my php files
@RiversideRocks after the download and everything, how do i locate the /vendor folder in my machine and mostly how do i move these folder to my webhost knowing thats where it belongs, not in my local MAMP or XAMPP machine?
Perfectly i think it worked, i now fully understand the use of composer, after i found where the folder was in my computer i copied the entire vendor folder into my website files and then required the request.php file according to the file path, and it worked,
So i can just move everything now to my website host including the vendor files?
Hope this does not have any security issues especially with the request.php file i dont even know the code it has inside it.
Just that am still having issues with
cURL error 60: SSL certificate problem: self signed certificate in certificate chain