API与WordPress的集成

时间:2012-10-11 作者:Jeces

我正在尝试将第三方API与WordPress集成。我担心这是我无法理解的。我是这个代码,但我不确定如何在WordPress中工作。有可能吗?

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, \'https://xxx\');
curl_setopt($ch, CURLOPT_POST, 7);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
    \'auth_token\' => \'xxxxxx\',
    \'list_id\' => \'xxxxx,
    \'name\' => \'Office\',
    \'campaign_id\' => \'xxxxx\',
)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

1 个回复
SO网友:Otto

类似于这样的工作:

$url = \'https://xxx\';

$body = array(
    \'auth_token\' => \'xxxxxx\',
    \'list_id\' => \'xxxxx,
    \'name\' => \'Office\',
    \'campaign_id\' => \'xxxxx\',
);

$response = wp_remote_post($url, array(
    \'body\'=>$body, 
    \'sslverify\' => false // this is needed if your server doesn\'t have the latest CA certificate lists
    ) );

if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
    // error handling goes here
}

$results = wp_remote_retrieve_body( $response );
// $results has the actual results in it

结束

相关推荐

多站点中的设置API-缺少更新消息

当我在多站点安装中使用设置API时,选项页面位于网络级别,将选项发布到options.php 不工作,因为管理页面位于wp-admin/network WP希望页面位于wp-admin.我添加了一个函数,用于检查此WP安装是否是多站点安装(通过常量),如果是,则将表单的动作值更改为../option.php. 这将保存选项OK,但默认消息“Settings saved”(设置已保存)缺少(但是,查询字符串不包括settings-updated=true).如何让信息显示出来,有什么想法吗?