Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “如何修复”;“用户无效”;将用户添加到具有redmine API REST的组时出错_Php_Redmine Api - Fatal编程技术网

Php “如何修复”;“用户无效”;将用户添加到具有redmine API REST的组时出错

Php “如何修复”;“用户无效”;将用户添加到具有redmine API REST的组时出错,php,redmine-api,Php,Redmine Api,我想将一个用户分配给一个使用API REST的组 但它不起作用 我使用POST/groups/:id/users.:format语法(请参阅) 具有此id的用户也存在于redmine和组中 在redmine日志中,我可以看到: Processing by GroupsController#add_users as XML Parameters: {"group"=>{"user_id"=>"34"}, "key"=>"81aa228c55ac5cfe4264a566ef67

我想将一个用户分配给一个使用API REST的组

但它不起作用

我使用
POST/groups/:id/users.:format
语法(请参阅)

具有此id的用户也存在于redmine和组中

在redmine日志中,我可以看到:

Processing by GroupsController#add_users as XML
Parameters: {"group"=>{"user_id"=>"34"},   "key"=>"81aa228c55ac5cfe4264a566ef67ac27702da8eb", "id"=>"5"}
Current user: admin (id=1)
Rendering common/error_messages.api.rsb
Rendered common/error_messages.api.rsb (0.1ms)
Completed 422 Unprocessable Entity in 4ms (Views: 0.4ms |  ActiveRecord: 1.3ms)
在API的回复中:

Code Error :422
Message : User is invalid
In request body : id of user
我使用ActiveResourceforRESTAPI

$method = 'users'
$options = array('user_id' => user's id to add)

/**
 * Posts to a specified custom method on the current object via:
 *
 *     POST /collection/id/method.xml
 */
function post ($method, $options = array (), $start_tag = false) {
    $req = $this->site . $this->element_name_plural;
    if ($this->_data['id']) {
        $req .= '/' . $this->_data['id'];
    }
    $req .= '/' . $method . '.xml';
    return $this->_send_and_receive ($req, 'POST', $options, $start_tag);
}
此函数用于发送请求和解析响应:

/**
     * Build the request, call _fetch() and parse the results.
     */
    function _send_and_receive ($url, $method, $data = array (), $start_tag = false) {
        $params = '';
        $el = $start_tag ? $start_tag : $this->element_name; // Singular this time
        if ($this->request_format == 'url') {
            foreach ($data as $k => $v) {
                if ($k != 'id' && $k != 'created-at' && $k != 'updated-at') {
                    $params .= '&' . $el . '[' . str_replace ('-', '_', $k) . ']=' . rawurlencode ($v);
                }
            }
            $params = substr ($params, 1);
        } elseif ($this->request_format == 'xml') {
            $params = '<?xml version="1.0" encoding="UTF-8"?><' . $el . ">\n";
            foreach ($data as $k => $v) {
                if ($k != 'id' && $k != 'created-at' && $k != 'updated-at') {
                    $params .= $this->_build_xml ($k, $v);
                }
            }
            $params .= '</' . $el . '>';
        }

        if ($this->extra_params !== false) {
            if(strpos($url, '?'))
            {
                $url = $url .'&'.$this->extra_params;
            }
            else
            {
                $url = $url .'?'.$this->extra_params;
            }

        }

        $this->request_body = $params;
        $this->request_uri = $url;
        $this->request_method = $method;

        $res = $this->_fetch ($url, $method, $params);

        if ($res === false) {
            return $this;
        }

        // Keep splitting off any top headers until we get to the (XML) body:
        while (strpos($res, "HTTP/") === 0) {
            list ($headers, $res) = explode ("\r\n\r\n", $res, 2);
            $this->response_headers = $headers;
            $this->response_body = $res;
            if (preg_match ('/HTTP\/[0-9]\.[0-9] ([0-9]+)/', $headers, $regs)) {
                $this->response_code = $regs[1];
            } else {
                $this->response_code = false;
            }

            if (! $res) {
                return $this;
            } elseif ($res == ' ') {
                $this->error = 'Empty reply';
                return $this;
            }
        }

        // parse XML response
        $xml = new SimpleXMLElement ($res);

        // normalize xml element name in case rails ressource contains an underscore
        if (str_replace ('-', '_', $xml->getName ()) == $this->element_name_plural) {
            // multiple
            $res = array ();
            $cls = get_class ($this);
            foreach ($xml->children () as $child) {
                $obj = new $cls;
                foreach ((array) $child as $k => $v) {
                    $k = str_replace ('-', '_', $k);
                    if (isset ($v['nil']) && $v['nil'] == 'true') {
                        continue;
                    } else {
                        $obj->_data[$k] = $v;
                    }
                }
                $res[] = $obj;
            }
            return $res;
        } elseif ($xml->getName () == 'errors') {
            // parse error message
            $this->error = $xml->error;
            $this->errno = $this->response_code;
            return false;
        }

        foreach ((array) $xml as $k => $v) {
            $k = str_replace ('-', '_', $k);
            if (isset ($v['nil']) && $v['nil'] == 'true') {
                continue;
            } else {
                $this->_data[$k] = $v;
            }
        }

        return $this;
    }
/**
*构建请求,调用_fetch()并解析结果。
*/
函数_send_和_receive($url、$method、$data=array(),$start_tag=false){
$params='';
$el=$start\u标记?$start\u标记:$this->element\u name;//这次是单数
如果($this->request_format=='url'){
foreach($k=>v的数据){
如果($k!=“id”&&$k!=“创建于”&&$k!=“更新于”){
$params.='&'$el.['.str_replace('-','.'''',$k)。]='.rawurlencode($v);
}
}
$params=substr($params,1);
}elseif($this->request\u format=='xml'){

$params='您应该添加用于发送请求的代码,因为这可能是问题所在。您应该添加用于发送请求的代码,因为这可能是问题所在