我想将日期参数传递给PHP SDK批处理请求方法。
是否可以传递日期参数,例如:
$params = array(
'time_range' => array(
'since' => (new \DateTime("-1 week"))->format('Y-m-d'),
'until' => (new \DateTime())->format('Y-m-d'),
),
);
我的批量请求基本上是:
foreach( $campaign_ids as $campaign_id ) {
$batch[] = $fb->request('GET/', env("FB_APP_VERSION") . '/' . $campaign_id . '/insights?fields=impressions,unique_clicks,reach');
}
try {
$responses = $fb->sendBatchRequest($batch);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
答案 0 :(得分:0)
根据
我假设您可以为每个请求添加一个附加参数,如下所示:
格式:time_range={'since':'2015-01-01','until':'2015-01-20'}
在PHP中,这意味着您必须json_encode $params
数组并将其添加到每个请求中。
$time_range = array(
'since' => (new \DateTime("-1 week"))->format('Y-m-d'),
'until' => (new \DateTime())->format('Y-m-d'),
)
$fb->request('GET/', env("FB_APP_VERSION") . '/' . $campaign_id . '/insights?fields=impressions,unique_clicks,reach&time_range=' . json_encode($time_range));
答案 1 :(得分:0)
在阅读完源代码之后,我发现你可以在params中传递日期:(传递给请求处理程序时获取url_encoded)
setup.dll