Auto post to Twitter via admin Twitter Account

Rakesh Kumar

I have done with hook_node_insert function hook_node_insert($node){ // Only post certain types of nodes. $types = array('article', 'video', 'blog'); if(in_array($node->type, $types)){ module_load_include('inc', 'twitter'); // Here you could use any account, but we want the admin account. $account = user_load(1); $twitter_accounts = twitter_twitter_accounts($account); $twitter_account = $twitter_accounts[0]; $replacements = array( '!title' => $node->title, '!url' => url('node/' . $node->nid, array('absolute' => TRUE, 'alias' => TRUE)), '!url-alias' => url('node/' . $node->nid, array('absolute' => TRUE)), ); // Only generate the shortened URL if it's going to be used. No sense // burning through TinyURLs without a good reason. if (strstr($node->twitter['status'], '!tinyurl') !== FALSE) { $replacements['!tinyurl'] = twitter_shorten_url(url('node/' . $node->nid, array('absolute' => TRUE))); } // The given text will be posted to // You can use !url, !url-alias, !tinyurl, !title and !user as replacement text. $status = 'New post: !title !url-alias'; // Need to get default text here. $status = strtr($status, $replacements); if (twitter_set_status($twitter_account, $status))…

View original post 7 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s