• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Failed to retrieve access token

New Here ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

<?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;
}

TOPICS
How to , Scripting , SDK

Views

220

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2023 Mar 01, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines