将参数发送到 Drupal 视图(JSON、cURL)

发布于 2024-10-21 12:17:06 字数 891 浏览 2 评论 0原文

我正在尝试使用 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懷念過去 2024-10-28 12:17:06

您是否尝试过使用视图数据源?它打印出 JSON,并且您仍然可以将参数传递给您的视图。

我们无法知道您如何在视图中配置日期参数,但可以肯定的是,视图允许您配置日期参数:

“示例视图日期参数”

这是视图中的示例日期范围。

示例视图日期参数

在使用视图数据源的同时,您还可以继续使用 CURL 从视图中获取 JSON。然后您可以将日期传递到请求中,如下所示:

curl_setopt($ch, CURLOPT_URL, 'http://site.com/myjsonview/2011-01-11--2011-03-11');

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:

example views date argument

Here's an example date range in Views.

example views date argument

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:

curl_setopt($ch, CURLOPT_URL, 'http://site.com/myjsonview/2011-01-11--2011-03-11');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文