5

I'm getting in trouble where I was coding for connection using OpenX API with XML-RPC2. I get the problem that the data type is required by the fire function is the dateTime.iso8601.

This is my code:

$sdatetime = new DateTime('2013-01-01 00:00:00');
$edatetime = new DateTime('2013-06-01 00:00:00');

$startDate = $sdatetime->format(DateTime::ISO8601);
$endDate = $edatetime->format(DateTime::ISO8601);

try {
    $result = $aClient->agencyPublisherStatistics($sessionId, 1, $startDate, $endDate);
    print_r($result);
} catch (XML_RPC2_FaultException $e) {
    die('Exception #' . $e->getFaultCode() . ' : ' . $e->getFaultString());
}

This is result error, when I run script above:

Exception #3 : Incorrect parameters passed to method: Wanted dateTime.iso8601, got string at param 3

If I run print_r(gettype($startDate)); I get the type data is string not date.

My question, for variables $startDate and $endDate how to make their data type to be dateTime.iso8601 or date rather than string.

Thanks.

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
Loren Ramly
  • 1,091
  • 4
  • 13
  • 21
  • I do not know this api very well, but how about just passing the $sdatetime object? – nvanesch May 01 '13 at 09:40
  • Hi @nvanesch I have finished with this link http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php , thanks for help me. – Loren Ramly May 01 '13 at 10:35

3 Answers3

1

it looks like your agencyPublisherStatistics requires specific XML_RPC2_Value date object. You cancreate this by using.

$startDate = XML_RPC2_Value::createFromNative($startDate, ‘datetime’);

same for the end date.. let me know if this works..

Dinesh
  • 3,065
  • 1
  • 18
  • 19
  • I have finished with this link http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php , thanks for clue. – Loren Ramly May 01 '13 at 10:32
1

Try this,

$sdatetime = date(DATE_ISO8601, strtotime('2013-01-01 00:00:00'));
$edatetime = date(DATE_ISO8601, strtotime('2013-06-01 00:00:00')); 

OR

Check below links,

http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php

https://bugs.php.net/bug.php?id=51950

may this help you.

Tony Stark
  • 8,064
  • 8
  • 44
  • 63
  • Sorry not working, it will return type data as string, I have resolve with this link http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php – Loren Ramly May 01 '13 at 14:17
  • Don't, because for reference other people, I will give one up for your answer. Thanks. – Loren Ramly May 01 '13 at 14:20
  • No problem man, maybe other people got problem in php server bugs, because your answer there is link reference to the bug. – Loren Ramly May 01 '13 at 14:26
0

use DateTime::setISODate

$sdatetime = new DateTime('2013-01-01 00:00:00');
$edatetime = new DateTime('2013-06-01 00:00:00');

$startDate = $sdatetime->setISODate(2013);
$endDate = $edatetime->setISODate(2013);
Amir
  • 4,089
  • 4
  • 16
  • 28
  • I have finished with this link http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php , thanks for help me. – Loren Ramly May 01 '13 at 10:33