Solving Using node.save in services
module comes with some services by default. Service Node
makes available several services related to nodes. One is
node.save .
node.save to publish a node from another site. In particular, another Drupal site.
Without Keys Server
Assuming the site where we publish is
http://myserver.example.com , there is installed services. You have to activate the modules:
- Services
-
- XMLRPC Server Node Service
The management interface (admin / build / services) in the Browse tab, you can browse the available services.
As is turned Service Node, available:
- node.view
- node.get
- node.save
- node.delete
When you choose a service, it will show its syntax and form test. For node.save is required as a parameter an array node.
As the publication will be made as an anonymous user, you must give permission to create the kind of node we want. For example, if we thereby create a node of type 'job' then you have to give anonymous users permission for it. In addition to load node data permit node_service module.
Customer
In a client module, you can use code similar to:
mymodule_job_plandevuelo_publicar function ($ nid) {$
plandevuelo_url = 'http://myserver.example.com/ ';
$ node = node_load ($ nid);
$ node-> type =' job ';
unset ($ node-> nid);
$ xmlrpc_result = xmlrpc ($ plandevuelo_url. " xmlrpc.php ',' node.save ' $ node);
return $ xmlrpc_result;
} In this example, the client obtains its own tables, a node with nid specified. Then use the function to call xmlrpc node.save service on the server.
Note that the url is the xmlrpc.php file from the server. Also the name of the service is the second parameter xmlrpc (). Thereafter, the remaining parameters are passed in the same order to the function served by the service on the server. So, $ node will be the first parameter to the function it serves node.save.
While it is important to follow the rules of service, can sometimes be frustrating. For example,
to create a new node, the service requires that the node has no nid. If so, you get an Access Denied message. It also requires notification of the type of node (
'job' , in this example).
With Keys Server server is configured as in the case Without Keys.
activation is required, in addition, the modules:
-
- Key Authentication Service System
Also in the admin interface (admin / build / services), the tab
Options, choose the combo that authentication module is
Key authentication .
If you check Use keys, when you save the options, a Keys tab where you can define keys to limit access to services by domain.
For example, you could define a key
My Client, for the domain
myclient.example.com , marking
node.save there other services you want.
Leave the box for Use sessed include a session id to use in identification. The session ID is obtained using the
system.connect service. Entering
and choosing Browse
node.save , you can see that the syntax has changed and requires more parameters before
node.
a) If left unchecked
Use keys,
node.save require two parameters:
- sessed
-
node
b) If you check the option left Use keys, node.save require six parameters:
hash -
- domain_name
- domain_time_stamp
- nonce
- sessed
- node
Customer
a) Not Use keys If left unchecked
Use keys on the server, the client may use a code similar to:
mymodule_job_plandevuelo_publicar function ($ nid) {$
plandevuelo_url = 'http://myserver.example.com/' ;
$ node = node_load ($ nid);
$ node-> type = 'job';
unset ($ node-> nid);
$ domain_name = $ _SERVER ['HTTP_HOST'];
$ domain_time_stamp = (string) time () ;
/ / connect
$ method = ' system.connect ';
$ xmlrpc_result = xmlrpc ($ plandevuelo_url. 'xmlrpc.php', $ method);
$ sessed = $ Xmlrpc_result ['sessed'];
/ / save
$ method = ' node.save ';
$ xmlrpc_result = xmlrpc ($ plandevuelo_url. 'Xmlrpc.php', $ method, $
sessed ,
$ node);
return $ xmlrpc_result;}
Notice is now required to invoke system.connect
for sessed.
b) Use keys
If you check the option left Use keys on the server, you can use code similar to:
mymodule_job_plandevuelo_publicar function ($ nid) {$
plandevuelo_url = 'http://myserver.example.com/' ;
$ node = node_load ($ nid);
$ node-> type = 'job';
unset ($ node -> nid);
DOMAIN_NAME $ = $ _SERVER ['HTTP_HOST'];
$ domain_time_stamp = (string) time ();
/ / connect
$ method = ' system.connect ';
$ xmlrpc_result = xmlrpc ($ plandevuelo_url. "xmlrpc.php ', $ method);
$ sessid = $ xmlrpc_result [' sessid '];
/ / save
$ method =' node.save ';
$ Nonce = user_password ();
$ domain_time_stamp = (string) time ();
hash_hmac $ hash = ('sha256', $ domain_name domain_time_stamp .';'.$ .';'. $ nonce .';'.$ method, '90a84268ba54e7ea02571524586997db ');
$ xmlrpc_result = xmlrpc ($ plandevuelo_url.' xmlrpc.php ', $ method, $ hash
,
$ domain_name, $
domain_time_stamp,
$ nonce, $
sessed ,
$ node);
return $ xmlrpc_result;}
One way to update node.save required $ node-> nid plus a $ node-> date changed, eg
...
/ * / / CREATE
$ node-> type = 'job';
unset ($ node-> nid);
* /
/ / UPDATE
$ node-> nid = 16, $ node-
> changed = time ();
...
Some precautions Although this example I have come to
node.save nearly $ node directly
that obtained with
node_load () , I noticed that may be more convenient to form an array with only required values \u200b\u200band just pass the array to
node.save .
Otherwise, can have unexpected results. For example, if the local node has not enabled the option to comment, while the destination you want if I do, if you spend the entire node will also pass these preferences. Create a node without the feedback option or, to update, eliminate the comments that he had associated.
References: