将参数发送到 Drupal 视图(JSON、cURL)
我正在尝试使用 (Node)Date Created 参数检索视图。然而,当我通过 cURL 发送它时,我似乎无法让它正常工作。这是我的代码:
$method = 'views.get';
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'. $method, $api_key);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, 'http://site.com/services/json');
$date = $_GET['date'];
$data = array(
'method' => '"'. $method .'"',
'hash' => '"'. $hash .'"',
'domain_name' => '"'. $domain .'"',
'domain_time_stamp' => '"'. $timestamp .'"',
'nonce' => '"'. $nonce .'"',
'sessid' => '"'. $sessid .'"',
'view_name' => '"frontpage"',
'args' => '"'. $date .'"'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json_result = curl_exec($ch);
我以某种方式猜测它的处理参数,因为它返回 [] ,当我删除 'args' =>.... 时,它会使用通配符设置运行。
I'm trying to retrieve a view with the (Node)Date Created argument. However I don't seem to be able to get it to work right, when I send it though cURL. Here is my code:
$method = 'views.get';
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'. $method, $api_key);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, 'http://site.com/services/json');
$date = $_GET['date'];
$data = array(
'method' => '"'. $method .'"',
'hash' => '"'. $hash .'"',
'domain_name' => '"'. $domain .'"',
'domain_time_stamp' => '"'. $timestamp .'"',
'nonce' => '"'. $nonce .'"',
'sessid' => '"'. $sessid .'"',
'view_name' => '"frontpage"',
'args' => '"'. $date .'"'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json_result = curl_exec($ch);
I'm guessing its processing args somehow, as it returns [] with that, and when I remove 'args' =>.... it runs with the wildcard setting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用视图数据源?它打印出 JSON,并且您仍然可以将参数传递给您的视图。
我们无法知道您如何在视图中配置日期参数,但可以肯定的是,视图允许您配置日期参数:
这是视图中的示例日期范围。
在使用视图数据源的同时,您还可以继续使用 CURL 从视图中获取 JSON。然后您可以将日期传递到请求中,如下所示:
Have you tried using Views datasource? It prints out JSON, and you can still pass an argument to your view.
We have no way of knowing how you configured the date argument in your View, but it is certain that Views lets you configure a date argument:
Here's an example date range in Views.
And you can continue to use CURL to fetch the JSON from your View while using Views datasource as well. Then you could pass the date into the the request as such: