【发布时间】:2017-02-24 12:16:50
【问题描述】:
我正在 wordpress 中创建一个插件,它将根据从 api 接收到的数据创建自定义帖子。起初我有这个代码:
$stuff_request = 'https://thisdomain/api/stuff';
$username = 'thisdomainuser';
$password = 'thisdomainpassword';
$headers = array( 'Authorization' => 'Basic ' . base64_encode( "$username:$password" ) );
$stuff_response = wp_remote_get( $stuff_request, array( 'headers' => $headers ));
$stuff_data = json_decode($stuff_response, true);
但我收到了错误 “期望参数 1 是给定的字符串数组” 这向我暗示 $stuff_response 可能已经以正确的格式返回,所以我从季节数据中删除了 json_decode
$stuff_data = $stuff_response;
但这根本无法返回任何内容,并且调试中没有出现错误消息。这是我如何将 api 调用到插件中的问题,还是外部 api 的问题?
【问题讨论】:
-
var_dump($stuff_response); -
或 print_r($stuff_response);
-
感谢已将此添加到我的插件中,我将返回 null