titobrasolin / Drupal7.Services

.NET API to integrate with Drupal 7 via Services 3 module.
MIT License
7 stars 3 forks source link

create node with login but access deny #1

Closed chzhcpu closed 8 years ago

chzhcpu commented 8 years ago

I have logged in and creatnode , but throw a exception: access deny: here is my code:

        DrupalServices service = new Drupal7.Services.DrupalServices("http://**********");
        bool login = service.Login("*******", "*******");
        XmlRpcStruct node = service.NodeRetrieve(1);
        if (service.IsLoggedIn)
        {
            node["title"] = "123";
            service.NodeUpdate(node);
        }
titobrasolin commented 8 years ago

@chzhcpu Maybe your user's permissions are insufficient. Anyhow I'll investigate and let you know ASAP

chzhcpu commented 8 years ago

Thinks for your kind replay. Would you please give me an example of create or update a node?

titobrasolin commented 8 years ago

@chzhcpu Your code looks quite fine, but I think there's some issue with the XmlRpcStruct class. Please try these: 1) To update the node, do not assign a new value to its fields but remove and add them back like this:

    var node = service.NodeRetrieve(1);
    var oldTitle = node["title"];
    node.Remove("title");
    node["title"] = oldTitle + " (UPDATED)";
    node = service.NodeUpdate(Convert.ToInt32(node["nid"]), node);

2) You can "clone" a node like this (at first i thought it was necessary to remove the "nid", in fact it is not):

    var node = service.NodeRetrieve(1);
    var clone = service.NodeCreate(node);

You can combine 1) and 2) of course:

    var node = service.NodeRetrieve(1);
    node.Remove("title");
    node["title"] = "This is a clone";
    var clone = service.NodeCreate(node);

By the way, remember to check that your user has update and create permissions, and that the node you are retrieving actually exists.

titobrasolin commented 8 years ago

Update: "cloning" a node was in fact easier than i thought, I just updated the comment above accordingly.

chzhcpu commented 8 years ago

Thanks a lot. It works well.

ibuildit commented 8 years ago

I have the same access denied issue, my site is accessed as anonymous even after sucessful login (see the other issue I created)

ibuildit commented 8 years ago

Correction - if I DO NOT login I can access nodes.

When I AM LOGGED IN, I can't.

ibuildit commented 8 years ago

It also does not make any difference if I tick the session authentication in services config or not.

ibuildit commented 8 years ago

The access denied issue is resolved on my end (human error).