Go Back   vb.org Archive > vBulletin Modifications > Archive > Modification Graveyard
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
vBulletin to Twitter, live tweets of new threads Details »»
vBulletin to Twitter, live tweets of new threads
Version: 1.00, by buro9 buro9 is offline
Developer Last Online: Jul 2012 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 4.0.x Rating:
Released: 01-26-2010 Last Update: Never Installs: 272
Uses Plugins
Re-useable Code Additional Files Translations  
No support by the author.

This should work on all 4 and 3 versions of vBulletin as it's trivial.

Description:

You start a new thread, this hack makes a tweet about it on your twitter account.

This are live updates... not delayed, not based on RSS... the instant the thread is started, a tweet is made. This is how this hack differs from other hacks.

Why:

Mostly for SEO, but also as an alert system.

For SEO the idea is simply that search engines are drinking from the Twitter firehose and are indexing the links that are tweeted. Faster and increased indexing of your site benefits you by helping it be found.

For alerts it means that users are able to use whatever twitter client they wish to obtain updates. A lot of these provide filtering capabilities, so they're able to get a live filtered stream of updates that interest them. This works very well when you also use thread prefixes.

Pre-requisites:

You should have an account on bit.ly for URL shortening, and you should have an account on Twitter.

Go and register if you haven't yet:
http://bit.ly/
http://twitter.com/

Installation:

NOTE: Most problems are related to not putting your bit.ly or twitter user details in the plugin. Follow the instructions carefully!

Upload the two attached files to your forum root. These are twitter and bitly classes that enable the hack to work, you can also download these from the author:
http://classes.verkoyen.eu/bitly
http://classes.verkoyen.eu/twitter/

Go to the plugin manager and create a new plugin with the following details:
Product: vBulletin
Hook: newthread_post_complete
Title: Tweet to Twitter

PHP Code: [See below]

To configure the PHP code you need to know your bit.ly API key (go get it from bit.ly/account) and your username and password for twitter.

You also should make a list of the forumIds that are non-public as you will want to put these in the array provided.

i.e. if your admin forum is forumId = 7 and you also have a private forum for regular members which is forumid = 12, then you will want this:
$excludedForums = array(7, 12);

The PHP code should be this, with all of the relevant values for your forum inserted (replace everything bolded, including the < and > bits):
PHP Code:
// The array below are the ids of non-public forums, update these to be your admin forum ids or anything non-public by default
$excludedForums = array(0);

// If you are having trouble getting bitly URL shortening to work... disable it!
$useBitly true;

if (!
in_array($foruminfo[forumid], $excludedForums)) {
    
$shortUrl 'http://www.yourforumsdomain.com/showthread.php?t='.$newpost[threadid];

    if (
$useBitly) {
      
// http://classes.verkoyen.eu/bitly
      
require_once 'bitly.php';
      
$bitly = new Bitly('<bit.ly username>''<bit.ly API key>');
      
$shortUrl $bitly->shorten($shortUrl);
    }

    
$tweet '';
    if (isset(
$newpost['prefixid']) && $newpost['prefixid'] != '') {
        
$tweet $vbphrase['prefix_'.$newpost['prefixid'].'_title_plain'].' ';
    }
    
$tweet .= $newpost['title'].' '.$shortUrl;

    
// http://classes.verkoyen.eu/twitter/
    
require_once 'twitter.php';
    
$twitter = new Twitter('<twitter username>','<twitter password>');
    
$twitter->updateStatus($tweet);

So the bit.ly line might look like this after you've put your values in:
$bitly = new Bitly('testUser', 'R_hj3456hgf3hig56hi2gf6');
NOT
$bitly = new Bitly('<testUser>', '<R_hj3456hgf3hig56hi2gf6>');
See? Remove those <> bits, they just show what to replace.

The shortUrl line might look like this:
$shortUrl = 'http://www.vbulletin.com/forum/showthread.php?t='.$newpost[threadid];

The Twitter line might look like this:
$twitter = new Twitter('stephenfry','op1umisn1ce');

All make sense?

And that's it. Save and activate the plugin and create a test thread.

Now whenever a new thread is started, a tweet will be made to twitter instantly.

You can see this in effect here:
http://twitter.com/lfgss

That is being pushed new threads for http://www.lfgss.com/ and it's working perfectly.

Any questions?

FAQ (Frequently Asked Questions)

Q: It doesn't work!

A: That's not a question, however if it doesn't work then it's extremely likely you got your username and passwords wrong or left the < > signs in there. Double-check and do it again.

Q: I see an "INVALID_JSON" error

A: Disable bitly by setting $useBitly to false.
Q: I see an "You must be authenticated to access shorten" error

A: The credentials that you entered are either wrong, or you made a mess of the syntax. You did remove the < > when you put your values in right? Did you check the example given above?

Q: I see an error that says "Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in [path]/bitly.php"

A: Wow, that's a good one... but easily fixable. Insert this at line 136 (just after the CURL options) in bitly.php:
PHP Code:
$no_hack_needed = (ini_get('safe_mode') !== '1' && ini_get('open_basedir') === false);
if (
$no_hack_needed) {
  
$options[CURLOPT_FOLLOWLOCATION] = true;
} else {
  
$options[CURLOPT_FOLLOWLOCATION] = false;
  
$options[CURLOPT_HEADER] = true;

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #232  
Old 02-16-2010, 09:55 AM
lhridley lhridley is offline
 
Join Date: Dec 2009
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok, for those who want to post thread replies and new threads to twitter -- I think I figured this out.

1. Use the following to create a string for new threads (modify to suite you, but leave the datestamp portion in) -- keep the rest of the provided plugin code as is:

PHP Code:
$tweet '';
    if (isset(
$newpost['prefixid']) && $newpost['prefixid'] != '') {
        
$tweet .= date("YMj g:i:s a") . ' ' $vbphrase['prefix_'.$newpost['prefixid'].'_title_plain'].' ';
    }
    
$tweet .= date("Ydj g:i:s a") . ' ' .$newpost['title'].' '.$shortUrl;
    
$tweet .= ' new thread #mysearchterm'//replace #mysearchterm with something related to your forum 
2. Hook at newthread_post_complete

3. Use the following plugin code for replies:
PHP Code:
// The array below are the ids of non-public forums, update these to be your admin forum ids or anything non-public by default
$excludedForums = array();

// If you are having trouble getting bitly URL shortening to work... disable it!
$useBitly true;

if (!
in_array($threadinfo[forumid], $excludedForums)) {
    
$shortUrl 'http://www.myforumdomainname.co/showthread.php?t='.$threadinfo[threadid];

    if (
$useBitly) {
      
// http://classes.verkoyen.eu/bitly
      
require_once 'bitly.php';
      
$bitly = new Bitly('mybitlyaccountid''mybitlykey');
      
$shortUrl $bitly->shorten($shortUrl);
    }

    
$tweet '';
    
$tweet .= date("YMj g:i:s a") . ' ' $vbphrase['prefix_'.$threadinfo['prefixid'].'_title_plain'].' ';
    
$tweet .= $threadinfo['title'].' '.$shortUrl;
    
$tweet .= ' new reply #keyword'//again, use a #keyword related to your forum
    // http://classes.verkoyen.eu/twitter/
    
require_once 'twitter.php';
    
$twitter = new Twitter('mytwitteraccount','mypassword');
    
$twitter->updateStatus($tweet);

4. Use the following "two" hooks for the above code snippet:

newreply_post_ajax
newreply_post_complete

It looks like vBulletin triggers one or the other upon posting a new reply, but not both (and, most new posts will go through 'newreply_post_ajax'). vBulletin plugins are a new thing for me -- took a bit to figure this one out.

You can see a working feed at http://www.twitter.com/mediawikiusers
Reply With Quote
  #233  
Old 02-16-2010, 05:06 PM
tokenyank tokenyank is offline
 
Join Date: Jul 2005
Location: London
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

installed and working!

http://www.twitter.com/mumsonline

Thanks!
Reply With Quote
  #234  
Old 02-16-2010, 06:50 PM
lazydesis lazydesis is offline
 
Join Date: Sep 2006
Posts: 234
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

works perfectly in vb3.8 ...thanks for this
Reply With Quote
  #235  
Old 02-17-2010, 04:56 AM
mtlcore mtlcore is offline
 
Join Date: Jul 2005
Posts: 265
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great mod! Really worth it if someone teamed up with you to develop it into a full product.
I am getting this error though:

Quote:
Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in [path]/twitter.php on line 189
/statuses/update.xml Could not authenticate you.
Fatal error: Uncaught exception 'TwitterException' with message 'Unauthorized' in /home/mysite/public_html/forums/twitter.php:229 Stack trace: #0 /home/mysite/public_html/forums/twitter.php(648): Twitter->doCall('statuses/update...', Array, true) #1 /home/mysite/public_html/forums/newthread.php(273) : eval()'d code(26): Twitter->updateStatus('testing http://...') #2 /home/mysite/public_html/forums/newthread.php(273): eval() #3 /home/mysite/public_html/forums/vbseo.php(1129): require('/home/mysite/p...') #4 {main} thrown in /home/mysite/public_html/forums/twitter.php on line 229
I have curl enabled, safe_mode is off, open_basedir has a local value:

Quote:
home/mysite:/usr/lib/php:/usr/local/lib/php:/tmp
and no value under master value.

I've checked all the code in the plugin, all exactly the same as yours (with my info ofcourse).

bit.ly seems to be working fine since new URLs are being created, just not being posted to Twitter...

EDIT
I got it to work! BUT no bit.ly URL
Here what I did, I went into twitter.php and set the following to false.
$options[CURLOPT_FOLLOWLOCATION] = false;

now to solve the bit.ly issue.

Thanks
Reply With Quote
  #236  
Old 02-17-2010, 02:18 PM
hiker's Avatar
hiker hiker is offline
 
Join Date: Sep 2009
Posts: 221
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could I use this with multiple twitter accounts?

For example, I've got a hiking forum that I'd like to go to a hiking related twitter account, then I've got a mountain biking forum (same board) that I'd like to go to a different mountain biking related twitter account.

Is this possible?

Thanks, great mod regardless.
Reply With Quote
  #237  
Old 02-17-2010, 08:55 PM
whelck whelck is offline
 
Join Date: Jun 2004
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

After reading the entire thread, I have wonderfully concluded my error message is different from any other!


Expectation Failed on line 229 in /var/www/ufck/forums/twitter.php
#0 /var/www/ufck/forums/twitter.php(648): Twitter->doCall('statuses/update...', Array, true)
#1 /var/www/ufck/forums/newthread.php(262) : eval()'d code(26): Twitter->updateStatus('test http://bit...')
#2 /var/www/ufck/forums/newthread.php(262): eval()
#3 {main}


What is broken?
Reply With Quote
  #238  
Old 02-17-2010, 09:32 PM
Pro-eSports.com Pro-eSports.com is offline
 
Join Date: Jan 2010
Location: Germany
Posts: 263
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you select the forums you want to be tweeted? if not then this would be a great addition for future updates.
Reply With Quote
  #239  
Old 02-17-2010, 09:39 PM
whelck whelck is offline
 
Join Date: Jun 2004
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Pro-eSports.com View Post
Can you select the forums you want to be tweeted? if not then this would be a great addition for future updates.
You can select which forums you *don't* want tweeted, so you end up accomplishing the same thing.
Reply With Quote
  #240  
Old 02-17-2010, 09:49 PM
Pro-eSports.com Pro-eSports.com is offline
 
Join Date: Jan 2010
Location: Germany
Posts: 263
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome, I'm gonna install this great mod then.
Reply With Quote
  #241  
Old 02-18-2010, 02:16 AM
lhridley lhridley is offline
 
Join Date: Dec 2009
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by bogley View Post
Could I use this with multiple twitter accounts?

For example, I've got a hiking forum that I'd like to go to a hiking related twitter account, then I've got a mountain biking forum (same board) that I'd like to go to a different mountain biking related twitter account.

Is this possible?

Thanks, great mod regardless.
Yes, with some modifications. Contact me at webmaster@mwusers.com for more info.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10351 seconds
  • Memory Usage 2,353KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete