admin管理员组

文章数量:1327679

I created a plug-in that retrieves data from an api(at least tries to!). This is the code of the function.

function call_back(){

     
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$response = wp_remote_get ('',$args);
$args = array(

    'headers' => array(
      'Content-Type' => 'application/json',
      'Authorization' => 'Basic ', $apiKey,
    )
);


echo '<pre>';
var_dump(wp_remote_retrieve_body($response));
echo '</pre>';
};

The api key that i use works, used it in postman. But the problem i get is that in WP i get:

"string(95) "{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}""

I do have permission and the issue does exist, the problem is with authentication. For some reason i don't get access. Any idea on why?

I created a plug-in that retrieves data from an api(at least tries to!). This is the code of the function.

function call_back(){

     
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$response = wp_remote_get ('http://mysite.atlassian/rest/api/3/issue/LD-1',$args);
$args = array(

    'headers' => array(
      'Content-Type' => 'application/json',
      'Authorization' => 'Basic ', $apiKey,
    )
);


echo '<pre>';
var_dump(wp_remote_retrieve_body($response));
echo '</pre>';
};

The api key that i use works, used it in postman. But the problem i get is that in WP i get:

"string(95) "{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}""

I do have permission and the issue does exist, the problem is with authentication. For some reason i don't get access. Any idea on why?

Share Improve this question edited Jul 30, 2020 at 0:16 Jacob Peattie 44.1k10 gold badges50 silver badges64 bronze badges asked Jul 29, 2020 at 15:33 ThinsantaThinsanta 112 bronze badges 2
  • 3 You have to declare $args first – fuxia Commented Jul 29, 2020 at 15:46
  • What do you mean? Putting $args above the response? – Thinsanta Commented Jul 30, 2020 at 10:13
Add a comment  | 

1 Answer 1

Reset to default 1

Thank you that helped me alot! But there was one more problem and that was the "'Authorization' => 'Basic ', $apiKey," part. I just needed a dot before $apiKey. Thanks again for your help!

本文标签: pluginsWhat am is missing (API CORS)