node save using as2 and swx

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
timosea's picture

Ello,

I've just posted some swx as2 code http://drupal.org/node/289428#comment-1007620 as i'm having some issues with saving nodes via swx. I thought post a link here too as i'm still kind of green with services in drupal so my issue might not be with the swx module and just my logic in how the node save service works.

My demo user can edit node 111 (story) from drupal, so thought if I use swx to create a session and log that user in, then load node 111 then modify the title and save it, it should work, but must still doing something wrong as get "Access denied." as the result to node save, the non-existent session fault msg at the end is kind of concerning too.

Help would be most welcome;)

Comments

Access control

johannes-gdo's picture

you probably have to allow the following in Access control:

access content
create story content
edit own story content

good luck

Same prob

Fixdit's picture

I'm having exactly the same issue. I have set all the proper permissions. I get Access denied no matter what. Anyone having any luck at all saving nodes with SWX?

services node save

ygerasimov's picture

I have had similar problems working with REST server that is based on services. I have overcomed this using the patch http://drupal.org/node/723192. Please try it and let me know whether it was useful.

Thanks for the help

Fixdit's picture

Thanks for the help ygerasimov, but perhaps because I'm having to use ActionScript2 and Drupal 5 I'm not using the node_resource module. What is the key code in the patch above that solves the issue? Need help here, thanks.

don't think i can help

ygerasimov's picture

Sorry but I don't think I would be able to help. The problem with node_resource module was because of not passing $node object to node_access function. Make sure that you are logged in properly (try on server side somwhere to do watchdog and see the user in logs). In Drupal6 first you need to log in (get the sessid via cookies) and in next request (update of the node in your case) pass this cookie to server to be identified properly.

I have a feeling it is

Fixdit's picture

I have a feeling it is because Services now requires a HASH value as an API key, a timestamp, etc no matter what when saving a new node to the database. Anyone know how to generate a HASH value in ActionScript2?

This post got me

waldmanm's picture

This post got me going:
http://electricpineapple.net/2009/03/10/api-keys-to-the-city-setting-up-...

But it's for Drupal 6 and I think for AS3. Still, it might help.

I can't find a HASH key

Fixdit's picture

I can't find a HASH key generator for As2. I'm developing something for the mobile platform in Flash Lite so it's kinda limiting. I resorted to using a very very old version of services for Drupal 5 that didn't require a HASH value. It still didn't perform properly. Could this be something todo with the SWX module and it's permissions/access code?

A HASH isn't strictly

Michele Wickham's picture

A HASH isn't strictly required. When you go to site building->services in Drupal 6 there's a tab for settings where you can uncheck the requirement to use keys and session ID information for a given service. I have a setup currently that works without a hash so I know it's possible.

In a recent project, we had a blend of AS3 and AS2 components and I could not get the services to play nicely with AS2 at all due to the way NetConnection works - there was not a good way to get session ID back from the service upon connect. We ended up using an AS3 proxy and local connections to get around this. While this is clearly not an option for you, if you can safely not use the session ID and hash requirements, this may still work - this of course depends on what kind of data you need exposed.

Another issue may be in your user permissions, make sure there's enough permissions for either an authenticated or (if required) anonymous user to get to the service. If you need anonymous access to node information, you will need to allow that before the service will work. Again, consider security.

Checked the permissions over

Fixdit's picture

Checked the permissions over and over. Nothing :( The error comes from the Services module 'Access denied'. Is the SWX module not supplying something or putting arguments in a wrong order do yo think?

Also tried every which way to

Fixdit's picture

Also tried every which way to generate a node. I tried once logged in via flash to create a new node from scratch, which timed out. I then just tried creating a brand new node from scratch as an Anonymous user... timed out. I need to use AS2, SWX PHP and Drupal together. Please can someone lend some advice,
Cheers

OK... this became a massive

Fixdit's picture

OK... this became a massive pain, but I FINALLY got it to work.
The main thing was that after the login function I load up a node to update it like this:

function nodeHandler(event:Object) {
var nodeobj:Object = new Object();
  nodeobj = event.result;

   var callUpdateNode:Object = {serviceClass:"Drupal", method:"callService", args:['node.save', [nodeobj]], result:[this, confirmUpdateHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
   swx.call(callUpdateNode);
}

'nodeobj = event.result;' wasn't doing it when put inside the 'callUpdateNode' Object (like this '[nodeobj]'). It was as if the Object was empty, yet when you traced out the contents in Flash there was the data in there.

I solved this by assigning the loaded node to the 'nodeobj' like before ('nodeobj = event.result;'), but then re-assigned data to the final Object to be sent in the 'node.save' call:

function nodeHandler(event:Object) {
var nodeobj:Object = new Object();
  nodeobj = event.result;

   nodeobj = {
        nid:nodeobj.nid,
       vid:nodeobj.vid,
       type:nodeobj.type,
     status:nodeobj.status,
     created:nodeobj.created,
       changed:nodeobj.changed,
       comment:nodeobj.comment,
       promote:nodeobj.promote,
       sticky:nodeobj.sticky,
     revision_timestamp:nodeobj.revision_timestamp,
     title:nodeobj.title,
       body:nodeobj.body,
     teaser:nodeobj.teaser,
     log:nodeobj.log,
       format:nodeobj.format,
     uid:nodeobj.uid,
       name:nodeobj.name,
     picture:nodeobj.picture,
       data:nodeobj.data,
     last_comment_timestamp:nodeobj.last_comment_timestamp,
     last_comment_name:nodeobj.last_comment_name,
       comment_count:nodeobj.comment_count,
       taxonomy:nodeobj.taxonomy,
     body_value:nodeobj.body_value
      };

    var callUpdateNode:Object = {serviceClass:"Drupal", method:"callService", args:['node.save', [nodeobj]], result:[this, confirmUpdateHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
   swx.call(callUpdateNode);
}

This did the trick ;) If you need any details or further explanation contact me at Fixdit and I'll be happy to help.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: