【问题标题】:Wordpress User Data sent through cURL通过 cURL 发送的 Wordpress 用户数据
【发布时间】:2016-03-12 02:59:29
【问题描述】:

我刚刚将营销工具 Klaviyo 与我们的 Wordpress/WooCommerce 设置集成,我正在尝试通过 cURL API 推送用户元数据 - 但失败了!

您可以在此处了解 API 的工作原理:https://www.klaviyo.com/docs/http-api#people

我希望添加一个操作,这样当用户配置文件保存时,它会挂接到我的函数中,将元数据发送到 Klaviyo。

谁能看看我做错了什么 - 下面的代码?

非常感谢。

林茨

<?php

// Hook into the action which saves the User Meta Data (written by LD)

add_action( 'personal_options_update', 'klaviyo_send' );
add_action( 'edit_user_profile_update', 'klaviyo_send' );

function klaviyo_send () {

// Get cURL resource
$curl = curl_init();

// Set some options
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://a.klaviyo.com/api/identify?data=eyJ0b2tlbiI6ICJoYXFYaXEiLCAicHJvcGVydGllcyI6IHsiJGVtYWlsIjogInRob21hcy5qZWZmZXJzb25AZXhhbXBsZS5jb20iLCAiJGxhc3RfbmFtZSI6ICJKZWZmZXJzb24iLCAiUGxhbiI6ICJUcmlhbCIsICJTaWduIFVwIERhdGUiOiAiMjAxMy0wMS0yNyAxMjoxNzowNiIsICIkZmlyc3RfbmFtZSI6ICJUaG9tYXMifX0=',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
    'token' => 'haqXiq', //This is the public 'key' in Klaviyo
    '$email' => $user_id->email, //This translates the wordpress field into the Klaviyo field
    'twitter' => $user_id->twitter,
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

}

?>

【问题讨论】:

    标签: wordpress curl user-data


    【解决方案1】:

    尝试通过这种方式发送数据..将发布的数据更改为 url 友好的方式,如 ?key=value&amp;key=value&amp;key=value

      //extract data from the post
        //set POST variables
        $url = 'https://a.klaviyo.com/api/identify?data=eyJ0b2tlbiI6ICJoYXFYaXEiLCAicHJvcGVydGllcyI6IHsiJGVtYWlsIjogInRob21hcy5qZWZmZXJzb25AZXhhbXBsZS5jb20iLCAiJGxhc3RfbmFtZSI6ICJKZWZmZXJzb24iLCAiUGxhbiI6ICJUcmlhbCIsICJTaWduIFVwIERhdGUiOiAiMjAxMy0wMS0yNyAxMjoxNzowNiIsICIkZmlyc3RfbmFtZSI6ICJUaG9tYXMifX0=';
        $fields = array(
            'token' => 'haqXiq', //This is the public 'key' in Klaviyo
            '$email' => $user_id->email, //This translates the wordpress field into the Klaviyo field
            'twitter' => $user_id->twitter,
        );
    
        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string, '&');
    
        //open connection
        $ch = curl_init();
    
        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
    
        //execute post
        $result = curl_exec($ch);
    
        //close connection
        curl_close($ch);
    

    【讨论】:

    • 谢谢普拉卡什!明天我会试一试(在伦敦已经很晚了!),让你知道我过得怎么样!
    猜你喜欢
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2016-07-03
    • 2016-02-18
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多