drxrgundk062317205 2018-05-01 00:55
浏览 747

Eve Online ESI Curl授权

Trying my hand at using the new Eve ESI interface but am receiving the following error response when trying to authenticate:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Server: Microsoft-IIS/8.5
Request-Context: appId=cid-v1:2ccf88f2-29b9-460a-bc15-7c0b79926f61
Date: Tue, 01 May 2018 00:24:50 GMT
Connection: close
Content-Length: 0

Here is my code, using PHP/Curl:

<?php   
    $authcode = base64_encode("{my client ID}:{My Secret Key}");
    $data = array("grant_type" => "authorization_code", "code" => "{code returned by the server}");
    $data_string = json_encode($data);
    $ch = curl_init("https://login.eveonline.com/oauth/token");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, array("Content-Type:application/json", "Authorization: Basic " . $authcode)); 

    $result = curl_exec($ch); 

    print_r($result);

    curl_close($ch); 
?> 

Any ideas what I'm doing wrong? I've been following the user guide as closely as I can figure.

Thanks.

  • 写回答

1条回答 默认 最新

  • douyi2798 2018-05-18 04:37
    关注

    Try this:

        //Request Headers payload
        $headerData = array(
            "Authorization:Basic " . base64_encode("{my client ID}:{My Secret Key}"),
            "Content-Type:application/json", 
            'Host:login.eveonline.com'
        )
    
        //Request Body payload
        $bodyData = array(
            "grant_type" => "authorization_code", 
            "code" => "{code returned by the server}"
        );
    
        //Curl exec
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,"https://login.eveonline.com/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); 
    
        //Server response json decode & display
        $result = json_decode($result, true);
        print_r($result);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算