Skip to main content
Participant
March 2, 2023
Question

Failed to retrieve access token

  • March 2, 2023
  • 1 reply
  • 355 views

<?php

$login_url = 'http://192.168.2.187/login';
$login_data = array(
'username' => 'admin',
'password' => 'admin'
);

// Make the login request with the data as a POST request
$login_context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($login_data)
)
));
$login_response = file_get_contents($login_url, false, $login_context);
$login_http_code = http_response_code();

// Check if login was successful
if ($login_http_code === 200) {
// If successful, retrieve the access token from the response
$login_result = json_decode($login_response, true);
if (isset($login_result['access_token'])) {
$access_token = $login_result['access_token'];
echo "Access token: " . $access_token . "\n";

$api_url = 'http://192.168.2.187/illustrator';

// Make the API request with the access token as an Authorization header
$api_options = array(
'http' => array(
'method' => 'GET',
'header' => 'Authorization: Bearer ' . $access_token . "\r\n" .
'Content-Type: application/json'
)
);
$api_context = stream_context_create($api_options);
$api_response = file_get_contents($api_url, false, $api_context);

// Check if API request was successful
if ($api_response === false) {
echo "Failed to connect to API URL: $api_url";
} else {
$api_data = json_decode($api_response, true);
var_dump($api_data);
}
} else {
echo "Failed to retrieve access token";
}
} else {
// If unsuccessful, show error message
echo "Login failed: " . $login_response;
}

This topic has been closed for replies.

1 reply

Community Expert
March 2, 2023

Isn't this PHP code? What help do you need regarding this on Adobe forums? Provide some context of your problem, this is not how you will get any worthwhile responses

-Manan

-Manan