Problem with eve ESI "invalid_client"

Hi all.

I started to develop a small web based (php) application using the ESI API. Here is my code right now.

<?php
    $authcode = base64_encode("{CLIENT_ID}:{SECRET_KEY}");
    $data = array("grant_type" => "authorization_code", "code" => $_GET["code"]);
    $data_string = json_encode($data);
	
    $ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "https://login.eveonline.com/v2/oauth/token");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_HEADER, array("Content-Type:application/json", "Authorization:Basic " . $authcode)); 

    $result = curl_exec($ch);
	
	if (curl_error($ch))
	{
		$error_msg = curl_error($ch);
		print_r($error_msg);
	}
	curl_close($ch);
	
	print_r($result);
?> 

And this is my output…

HTTP/1.1 401 Unauthorized Cache-Control: no-cache Pragma: no-cache Content-Length: 87 Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.5 Date: Fri, 14 Dec 2018 21:11:59 GMT {“error”:“invalid_client”,“error_description”:“Missing or invalid client credentials.”}

Any help will be appreciated.

I solved it myself with google help:

$headerData = array(
“Authorization:Basic " . base64_encode(”{CLIENT_ID}:{SECRET_KEY}");
, “Content-Type:application/json”
, “Host:login.eveonline.com”
);

//Request Body payload
$bodyData = array(
“grant_type” => “authorization_code”
, “code” => $_GET[“code”]
);

//Curl exec
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,“https://login.eveonline.com/v2/oauth/token”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.