jjzjj

php - Drupal 7 - 无法显示服务端点

coder 2024-05-02 原文

我已经无计可施了,想弄清楚为什么这行不通。我正在尝试从我的 Drupal 7 实例设置一个 REST 服务器。目前专注于无需身份验证(一旦我设法让它说话,我就会设置它)。

这里是相关的代码位:

我的模块.module

/**
 * Implements hook_ctools_plugin_api().
 * Declares the mymodule services endpoint (stored in
 * mymodule.services.inc).  Note that the referenced ctools
 * hook obviates creating this endpoint through the UI.
 */
function mymodule_ctools_plugin_api($owner, $api) {
  if ($owner == 'services' && $api == 'services') {
    return array(
      'version' => 3,
      'file' => 'mymodule.services.inc',
      'path' => drupal_get_path('module', 'mymodule'),
    );
  }
}
/**
 * Implements hook_services_resources
 * Defines the resources available via services module (REST, in this case).
 *
 * @return array The definition array
 */
function mymodule_services_resources() {
  watchdog('mymodule', __FUNCTION__, array(), WATCHDOG_NOTICE, 'link');
    return array(
      '#api_version' => 3001,
      'test' => array(
        'retrieve' => array(
          'help' => t("A test of the REST api"),
          'file' => array(
            'type' => 'inc',
            'module' => 'mymodule',
            'name' => 'resources/test_resource',
          ),
          'access arguments'=>array('access content'),
          'callback' => 'mymodule_services_test',
          'args' => array(
            array(
              'name' => 'id',
              'type' => 'int',
              'description' => t("a test of rest arguments"),
              'source' => array('path' => '0'),
              'optional' => FALSE,
            ),
          ),
        ),
        'index' => array(
          'help' => t('A test of the REST api index functionality'),
          'file' => array(
            'type' => 'inc',
            'module' => 'mymodule',
            'name' => 'resources/test_resource',
          ),
          'callback' => 'mymodule_services_test',
        ),

      ),
    );
}

resources/test_resources.inc

/**
 *
 */
function mymodule_services_test() {
  watchdog('mymodule', __FUNCTION__, array(), WATCHDOG_NOTICE, 'link');
  $result = array('foo' => 'bar');
  drupal_json_output($result);
}
/**
 * Access callback for test services (currently unused)
 * @param  string $op   The operation being performed: creat
 * @param  [type] $args [description]
 * @return [type]       [description]
 */
function mymodule_services_test_access($op, $args) {
  watchdog('mymodule', __FUNCTION__, array(), WATCHDOG_NOTICE, 'link');
  return TRUE;
}

mymodule.services.inc

/**
 * @file
 */

/**
 * Implements hook_default_services_endpoint().
 */
function mymodule_default_services_endpoint() {
  watchdog('mymodule', __FUNCTION__, array(), WATCHDOG_NOTICE, 'link');
  $endpoint = new stdClass();
  $endpoint->disabled = FALSE;  //Edit this to true to make a default endpoint disabled initially
  $endpoint->api_version = 3;
  $endpoint->name = 'mymodule_rest_api_v1';
  $endpoint->server = 'rest_server';
  $endpoint->path = 'api/mymodule/v1';
  $endpoint->authentication = array();
  $endpoint->server_settings = array(
    'formatters' => array(
      'json' => TRUE,
      'bencode' => FALSE,
      'jsonp' => FALSE,
      'php' => FALSE,
      'xml' => FALSE,
    ),
    'parsers' => array(
      'application/json' => TRUE,
      'text/xml' => TRUE,
      'application/vnd.php.serialized' => FALSE,
      'application/x-www-form-urlencoded' => FALSE,
      'application/xml' => FALSE,
      'multipart/form-data' => FALSE,
    ),
  );
  $endpoint->resources = array();
  $endpoint->debug = 0;
  return array('mymodule'=>$endpoint);
}

我删除了此服务的 UI 构建定义,可以看到它已从代码成功重新创建,另外,当我访问“api/mymodule/v1/”时,我看到消息“服务端点“mymodule_rest_api_v1”已设置成功。',所以我知道 hook_default_services_endpoint 和 hook_ctools_plugin_api 工作正常。

但是,无论出于何种原因,我都无法将 mymodule_services_resources 中定义的任何路径识别为有效。我已经删除了所有访问限制,多次清除缓存 - 总是,当我点击任何以“test”结尾的 url 时,我最终得到 404 未找到(例如 https://[my-domain]/api/mymodule/v1/testhttps://[my-domain]/api/mymodule/v1/test/1 都产生“未找到:找不到资源测试。”)。

如有任何建议,我们将不胜感激。

最佳答案

想通了。回发原因以防其他人遇到此问题。

hook_services_resources 声明了模块提供的资源。它不做的是启用这些资源。返回到我的服务端点的资源选项卡下,我发现“测试”作为可以公开的新资源可用。更重要的是,它没有启用。

启用它并将其导出到代码后,我能够将 mymodule_default_services_endpoint 的内容更改为:

function mymodule_default_services_endpoint() {
  watchdog('mymodule', __FUNCTION__, array(), WATCHDOG_NOTICE, 'link');
  $endpoint = new stdClass();
  $endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */
  $endpoint->api_version = 3;
  $endpoint->name = 'mymodule_rest_api_v1';
  $endpoint->server = 'rest_server';
  $endpoint->path = 'api/mymodule/v1';
  $endpoint->authentication = array(
    'services' => 'services',
  );
  $endpoint->server_settings = array(
    'formatters' => array(
      'json' => TRUE,
      'bencode' => FALSE,
      'jsonp' => FALSE,
      'php' => FALSE,
      'xml' => FALSE,
    ),
    'parsers' => array(
      'application/json' => TRUE,
      'text/xml' => TRUE,
      'application/vnd.php.serialized' => FALSE,
      'application/x-www-form-urlencoded' => FALSE,
      'application/xml' => FALSE,
      'multipart/form-data' => FALSE,
    ),
  );
  $endpoint->resources = array(
    'test' => array(
      'operations' => array(
        'retrieve' => array(
          'enabled' => '1',
        ),
        'index' => array(
          'enabled' => '1',
        ),
      ),
    ),
  );
  $endpoint->debug = 0;
  return array('mymodule' => $endpoint);
}

现在我遇到了身份验证错误,这是我预料到的并且可以处理。希望这对某人有帮助。

关于php - Drupal 7 - 无法显示服务端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33511364/

有关php - Drupal 7 - 无法显示服务端点的更多相关文章

  1. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  4. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  5. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  6. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  7. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  8. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  9. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  10. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

随机推荐