hi I have a simple question which bugs me the last 2 days. Only one line of code. Why does this give a 404?

function mymodule_node_insert($node) 
{
	dprint_r(get_headers('http://www.urltoSite.com/node/' . $node->nid));
}

When visiting the created node (or checking headers again) after the submit, everything is fine (200 header).

That is how far I am...

menu_get_item($path) returns false because of this

 $map = _menu_translate($router_item, $original_map);
      $router_item['original_map'] = $original_map;
      if ($map === FALSE) {
       $router_items[$path] = FALSE;
        return FALSE;
      }

Comments

nevets’s picture

It is not at all clear what you are trying to do. I do not think the node exists completely at the point hook_node_insert() is called.

kris digital’s picture

Hi thanks for the reply. I am posting the new created node to facebook, the node has special header information like an image and a namespace, thats why at the moment of insertion the node must be available, so that fb can check the headers, but now 404 is returned. I am working with a fresh install, no custom modules.

I narrowed it down to the node_load function in menu.inc _menu_load_objects...

When I check the node_load in the insert_hook, everything is fine. So the node is there already. But when doing the Header Request as anonymous user (fb) node_load returns false at that moment. When I do the same request afterwards from somewhere else I get a 200 as expected.

I am stuck in the entity_load functions at the moment, I do not know why they return nothing. It is probably not in the database but in the cache, session or something wired.

nevets’s picture

Two things

There are modules for posting content to facebook.

And the way you post to facebook you do not pass the whole node, you pass information about the node which is available in $node.

kris digital’s picture

yes I work wit one module for the basic stuff, I can post things to walls and so on, no problem. But for the new timeline stuff there has to be a content in place when you call the fb api. I even tried to do it in the _exit hook, but I always get 404. No chance...

nevets’s picture

Is the content viewable by anonymous users?

kris digital’s picture

yes it is... if I make a header request from anywhere after the submission is complete I get a 200 header. Even if I put an exit() behind the header_request in the insert hook. The node is in the database at that moment, so why could node_load return false, and only at this special time and for another user? The parameters of the node_load are all ok...

nevets’s picture

I looked at the code, at that point the node is not fully saved, there are still things to do (this includes nodes grants and clearing cache). The facebook code I have looked at actually outputs javascript so the action is delayed till the next page load.

kris digital’s picture

Hi nevets,

thank you very much for the help. I tried setting the node grants and cleared the cache before checking with no efforts... Could you send me the code you are speaking of? As a workaround I also use another link which does a javascript redirect to the right location at the moment... But I don't really like that solution because of the extra reload...

nevets’s picture

Look in node.module for 'insert'. I would not recommend modify your code though to do what it does, it means other modules may not work as expected.

kris digital’s picture

yeah you are right, I just wanted to try it out... But I think I just found a solution in the kitchen that works for me, but I will check it first...

kris digital’s picture

So now I use an extra page to submit things to facebook. In the insert hook I do a drupal_goto to the fb post page with the nid appended and from there I make a goto to the original destination. I put my module to the bottom of the module table, so that no other modules' insert hooks are skipped...