【问题标题】:How to get data using curl or API from http://developers.bringg.com/docs/users如何使用 curl 或 API 从 http://developers.bringg.com/docs/users 获取数据
【发布时间】:2016-03-05 10:34:38
【问题描述】:

我只想在我的 wordpress 自定义插件中为自定义字段 Driver_info 使用 curl 来自 http://developers.bringg.com/docs/users 的名称。

 {
    extract($_POST);
    $url = 'http://parklee.loc/my-spaces-2/';
    $url = 'http://api.bringg.com/partner_api/users'; 

    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_POST,1); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, "id=2"); 
    $result = curl_exec($ch); 
    echo "<pre>"; print_r($result); 
    curl_close($ch);
}

请告诉我这段代码有什么问题。我收到错误 404,未找到。 我在里面写了这行代码

{
    function order_my_custom( $post ){
        $shipping = get_post_meta( $post->ID, 'driver_info', true );

        wp_nonce_field( 'save_BFM_shipping', 'BFM_shipping_nonce' );

        woocommerce_wp_select( array( 'id' => 'driver_info', 'label' => __('Driver Info: ', 'woocommerce'), 'options' => array(
            'OPTION1' => __('c1', 'woocommerce'),
            'OPTION2' => __('c2', 'woocommerce')
            ) ) );

    }
}

而我的名字不是 c1,c2。

【问题讨论】:

  • 我认为你没有完全按照指令。
  • 这个 api 需要一个company_id 并且你需要发送access_tokensignature 看起来也是如此

标签: php ajax wordpress curl


【解决方案1】:

阅读如何获取用户的文档,需要发送company_id作为参数

$data = [
    'company_id' => $id,
    // paginating data is good, even if it is optional
];

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),
    ),
);
$context  = stream_context_create($options);
$response = json_decode(file_get_contents('http://api.bringg.com/partner_api/users', false, $context));

现在你只需要在你的响应变量中,你可以转储它来查看它的内容并知道如何循环它

【讨论】:

    猜你喜欢
    • 2017-11-10
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 2015-04-02
    • 2015-11-17
    相关资源
    最近更新 更多