使用XML-RPC将日期发送到OpenX

时间:2010-08-27 20:29:25

标签: php xml-rpc openx

我正在尝试使用XML-RPC API在openX中插入一个广告系列,除了开始日期和结束日期之外的所有内容都正常工作,我当前的代码如下所示:

$campaign = new XML_RPC_Value(
                    array('advertiserId' => new XML_RPC_Value($advertiserID, 'int'),
                            'campaignName' => new XML_RPC_Value('My Banner', 'string'),
                            'startDate' => new XML_RPC_Value(new Date(time()), 'DateTime'),
                            'endDate' => new XML_RPC_Value(new Date(time() + (3600*24*3), 'DateTime')/*3 days into the future*/,
                            'impressions' => new XML_RPC_Value(10000, 'int'),
                            'clicks' => new XML_RPC_Value(-1, 'int'),
                            'priority' => new XML_RPC_Value(1, 'int'),
                            'weight' => new XML_RPC_Value(0, 'int')
                    ), 
                    'struct');

我正在使用PEAR XML_RPC包。此代码运行正常而不会产生任何错误,但是当我查看OpenX控制面板时,我的新广告系列没有开始日期或结束日期(它们设置为“立即开始”和“不要过期”)。

日期需要采用什么格式,OpenX才能接受它?

2 个答案:

答案 0 :(得分:2)

编辑:查看http://pear.php.net/package/XML_RPC代码,您需要自己将日期编码为ISO 8601字符串:

试试这样:

$campaign = new XML_RPC_Value(
                array('advertiserId' => new XML_RPC_Value($advertiserID, 'int'),
                        'campaignName' => new XML_RPC_Value('My Banner', 'string'),
                        'startDate' => new XML_RPC_Value(date('c'), 'dateTime.iso8601'),
                        'endDate' => new XML_RPC_Value(date('c', time() + (3600*24*3)), 'dateTime.iso8601')/*3 days into the future*/,
                        'impressions' => new XML_RPC_Value(10000, 'int'),
                        'clicks' => new XML_RPC_Value(-1, 'int'),
                        'priority' => new XML_RPC_Value(1, 'int'),
                        'weight' => new XML_RPC_Value(0, 'int')
                ), 
                'struct');

(XML-RPC日期类型为'dateTime.iso8601',而不是'DateTime'。)

答案 1 :(得分:0)

你读过这个吗? Changing date format 它应该能够告诉您它是如何设置的,然后您可以以这种方式输入或更改它以满足您的需要。