drnzpd579935 2019-08-12 14:30
浏览 167

GET API,返回结果,如何发布它们

I have been issued to call this API from a Car company and post it to WordPress posts with custom fields. I can successfully call the API in postman, below is the code I have generated from Postman. My next stage is to connect to WordPress and send this data so that each post will have one full set of information about said car. My PHP knowledge is rather basic, I believe I will be using the wp_remote_get and wp_remote_post, utilizing the REST API in order to get started what would you suggest I start with. Do I create a plugin which then runs in the background, or do I create a theme with Functions.php I am unsure at current what would be the best working practice. I understand this is probably vague but after researching and watching videos, all are using API feeds which don't require authentication. So I am a bit stuck, any advice would be fully appreciated.

        <?php

        $client = new http\Client;
        $request = new http\Client\Request;

        $request->setRequestUrl('https://api.****.net/APIv2/Vehicles/StockList');
        $request->setRequestMethod('GET');
        $request->setQuery(new http\QueryString(array(
        'stockListOptionModel.includeusedvehicles.includeImageDetails.includeVideoDetails' => 'true'
        )));

        $request->setHeaders(array(
        'cache-control' => 'no-cache',
        'Connection' => 'keep-alive',
        'Host' => 'api.***.net',
        'Postman-Token' => '79e50f16-0d32-402e-9586-34d7bc8fc590,0741d89a-02d8-4b50-8633-0f3c2eba8c1c',
        'Cache-Control' => 'no-cache',
        'User-Agent' => 'PostmanRuntime/7.15.2',
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Accept-Encoding' => 'gzip, deflate',
        'OrganisationalUnit_UID' => 'a3db2a66-***-4ac2-a78a-0f042aab50af',
        'Password' => '***',
        'UserName' => 'api@*****.co.uk',
        'Accept' => 'application/json'
        ));

        $client->enqueue($request)->send();
        $response = $client->getResponse();

        echo $response->getBody();
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题