vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Graveyard (https://vborg.vbsupport.ru/forumdisplay.php?f=224)
-   -   Miscellaneous Hacks - vBulletin to Twitter, live tweets of new threads (https://vborg.vbsupport.ru/showthread.php?t=234288)

buro9 01-26-2010 10:00 PM

vBulletin to Twitter, live tweets of new threads
 
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;



MOGmartin 01-27-2010 12:44 PM

I use a self built system very similar to this as well on my site....

the twitter account is http://twitter.com/seoforumsorg - and the board is at http://seoforums.org

from my experience I get around 50-80 new visitors per day using this method, so its recommended by me!

Great Work for sharing this with the community!

buro9 01-27-2010 12:51 PM

I'm seeing similar numbers. I also think that if you use Friendfeed and hook it up to pull in Twitter that you get double-benefit from it.

hiker 01-27-2010 01:05 PM

Sounds great, I'll install later this week.

Does this work when ANY thread is started, or just any started by ME? I assume it's any thread.

And does it have the ability to leave certain threads excluded?

Thanks.

buro9 01-27-2010 01:13 PM

It works for *ALL* threads by everyone.

Currently the only exclusion is to prevent threads started in specific forums from creating tweets.

All existing threads are not tweeted, this code tweets new threads only.

hiker 01-27-2010 02:30 PM

Quote:

Originally Posted by buro9 (Post 1967963)
It works for *ALL* threads by everyone.

Currently the only exclusion is to prevent threads started in specific forums from creating tweets.

All existing threads are not tweeted, this code tweets new threads only.

Thanks, I should have clarified - exclude certain FORUMS ... not threads.

I've got an outdoor forum with a general discussion forum. I'd like to exclude the general discussion forum and only tweet the outdoor related forums.

Thanks again, I'll be installing this week.

buro9 01-27-2010 02:40 PM

Ah, it does that... just add the "general" forum to the array of excluded forumIds. Job done.

Moondust 01-27-2010 04:52 PM

Hi, this is not Working, after a new Thread comming the follow Error

You must be authenticated to access shorten on line 193 in /home/erotidbr/erotikforen/forum/bitly.php
#0 /home/erotidbr/erotikforen/forum/bitly.php(382): Bitly->doCall('shorten', Array)
#1 /home/erotidbr/erotikforen/forum/newthread.php(262) : eval()'d code(10): Bitly->shorten('http://www.erot...')
#2 /home/erotidbr/erotikforen/forum/newthread.php(262): eval()
#3 {main}

Warnung: Invalid error type specified in [path]/vb/vb.php (Zeile 284)

Nordinho 01-27-2010 06:02 PM

Could vbseo be interfering with this? Also, if your forum not in root, what settings do you recommend? Getting the error below. Allthough a post on bit.ly gets made. Just not in Twitter.

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]/bitly.php on line 141
{ "errorCode": 0, "errorMessage": "", "results": { "http://www.domain.net/forumdir/showthread.php?t=44434": { "hash": "bi7V5B", "shortCNAMEUrl": "http://bit.ly/d0s0TB", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/d0s0TB", "userHash": "d0s0TB" } }, "statusCode": "OK" }
Fatal error: Uncaught exception 'BitlyException' with message 'Invalid JSON-response' in /home/domain.net/public_html/forumdir/bitly.php:196 Stack trace: #0 /home//domain.net/public_html/forumdir/bitly.php(382): Bitly->doCall('shorten', Array) #1 /home/domain.net/public_html/forumdir/newthread.php(273) : eval()'d code(20): Bitly->shorten('http://www.domain...') #2 /home/domain.net/public_html/forumdir/newthread.php(273): eval() #3 /home/domain.net/public_html/forumdir/vbseo.php(1440): require('/home/dom...') #4 {main} thrown in /home/domain.net/public_html/forumdir/bitly.php on line 196
I tried the full path, however then I get this error;

Quote:

Fatal error: Class 'Bitly' not found in /home/domain.net/public_html/forumdir/newthread.php(273) : eval()'d code on line 19
btw; using vb3.8

buro9 01-27-2010 06:31 PM

@Moondust

Your error appears to be this: "You must be authenticated to access shorten "

Did you insert your bit.ly username and API key?
You probably want to insert your twitter details too.

The instructions do say to put your values in there.

@Nordinho

I'm using vbseo, and I'm using both 3.8 and 4.0. So no, it's not vbseo that is causing it, and it's not 3.8 causing it.

Could it be this: "CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode "?

Are you in safe mode?

Nordinho 01-27-2010 06:34 PM

Quote:

Originally Posted by buro9 (Post 1968233)
@Nordinho

I'm using vbseo, and I'm using both 3.8 and 4.0. So no, it's not vbseo that is causing it, and it's not 3.8 causing it.

Could it be this: "CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode "?

Are you in safe mode?

Nope, I'm not in safe mode.

buro9 01-27-2010 06:56 PM

@Nordinho

It appears to be a PHP cURL thing.

Could you try inserting this at line 136 (just after the CURL options) in bitly.php
[edit]snippped, see post 22[/edit]

IF twitter.php also needs it, then it's line 161 of that (after the options) where it will need to be inserted.

Try just putting it in bitly.php to start with and let me know how it goes.

LbR 01-27-2010 06:58 PM

Works Now :D

utahraves 01-27-2010 06:59 PM

I installed this, followed all directions, do not get errors, but do not see the post happening on Twitter.
twitter.com/utahraves
Posted several tests then deleted them after wards but still not posting

EDIT: Ahhhh, It wasn't really clear to me the ARRAY deal. I believe I fixed it now. I'll test

buro9 01-27-2010 07:13 PM

Quote:

Originally Posted by LbR (Post 1968260)
Getting this error

PHP Code:

You must be authenticated to access shorten on line 193 in /home/emonxco/public_html/forum/bitly.php
#0 /home/emonxco/public_html/forum/bitly.php(382): Bitly->doCall('shorten', Array)
#1 /home/emonxco/public_html/forum/newthread.php(262) : eval()'d code(10): Bitly->shorten('http://www.emon...')
#2 /home/emonxco/public_html/forum/newthread.php(262): eval()
#3 {main}


WarningInvalid error type specified in [path]/vb/vb.php on line 284 


The pertinent line: You must be authenticated to access shorten

Have you put in your bit.ly and twitter details?

buro9 01-27-2010 07:18 PM

Quote:

Originally Posted by utahraves (Post 1968261)
EDIT: Ahhhh, It wasn't really clear to me the ARRAY deal. I believe I fixed it now. I'll test

I've just made it clearer by splitting it out, and I've set it to exclude nothing by default.

LbR 01-27-2010 07:20 PM

Quote:

Originally Posted by buro9 (Post 1968268)
The pertinent line: You must be authenticated to access shorten

Have you put in your bit.ly and twitter details?


I have added Twitter Details and Bit.Ly details too i am not confirmed about this line

$shortUrl = $bitly->shorten('http://www.yourforumsdomain.com/showthread.php?t='.$newpost[threadid]);

utahraves 01-27-2010 07:22 PM

Works now. The array is for forums that are NOT supposed to post twitter updates... got it :)

Moondust 01-27-2010 07:23 PM

Quote:

Originally Posted by buro9 (Post 1968233)
@Moondust

Your error appears to be this: "You must be authenticated to access shorten "

Did you insert your bit.ly username and API key?
You probably want to insert your twitter details too.

The instructions do say to put your values in there.

Yes, i have edit the Bit.ly username and Api Key and my Twitter Account Detail in the Plugin PHP Text.

In Bit.ly i have put my twitter account details

buro9 01-27-2010 07:25 PM

Quote:

Originally Posted by LbR (Post 1968278)
I have added Twitter Details and Bit.Ly details too i am not confirmed about this line

$shortUrl = $bitly->shorten('http://www.yourforumsdomain.com/showthread.php?t='.$newpost[threadid]);

Did you put your domain in there?

Nordinho 01-27-2010 07:28 PM

Quote:

Originally Posted by buro9 (Post 1968257)
@Nordinho

It appears to be a PHP cURL thing.

Could you try inserting 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) {
            
$curl_opts[CURLOPT_FOLLOWLOCATION] = true;
        } else {
            
$curl_opts[CURLOPT_FOLLOWLOCATION] = false;
            
$curl_opts[CURLOPT_HEADER] = true;
        } 

IF twitter.php also needs it, then it's line 161 of that (after the options) where it will need to be inserted.

Try just putting it in bitly.php to start with and let me know how it goes.

Hey buro,

Tried adding it in both files, unfortunately it doesn't make a difference though. Getting the same error.

buro9 01-27-2010 07:33 PM

Quote:

Originally Posted by Nordinho (Post 1968286)
Hey buro,

Tried adding it in both files, unfortunately it doesn't make a difference though. Getting the same error.

My fault... it should've been this for 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;



wacnstac 01-27-2010 07:36 PM

Why not just grab the RSS out from the forum in twitter and feed it to your twitter account with twitterfeed? Am I missing something?

buro9 01-27-2010 07:39 PM

Quote:

Originally Posted by wacnstac (Post 1968295)
Why not just grab the RSS out from the forum in twitter and feed it to your twitter account with twitterfeed? Am I missing something?

The live aspect of it.

wacnstac 01-27-2010 07:42 PM

Ah, I get it now :)

esperone 01-27-2010 07:42 PM

I get same error as LbR and i have edited the php code to include my bit.ly username and API key as well as my twitter details.

buro9 01-27-2010 07:45 PM

Quote:

Originally Posted by esperone (Post 1968306)
I get same error as LbR and i have edited the php code to include my bit.ly username and API key as well as my twitter details.

LbR PM'd me... he'd put the username between the < >.

I've just updated the hack instructions to show examples... the details you enter are just PHP strings and should be single-quoted.

esperone 01-27-2010 07:48 PM

oh i see. Thanks.

Nordinho 01-27-2010 07:49 PM

Quote:

Originally Posted by buro9 (Post 1968292)
My fault... it should've been this for 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;



Allrighty, the curl error is gone. Now on to the next one ;)

This one remains:
Quote:

Fatal error: Uncaught exception 'BitlyException' with message 'Invalid JSON-response' in /home/domain.net/public_html/forumdir/bitly.php:204 Stack trace: #0 /home/domain.net/public_html/forumdir/bitly.php(390): Bitly->doCall('shorten', Array) #1 /home/domain.net/public_html/forumdir/newthread.php(273) : eval()'d code(20): Bitly->shorten('http://www.nord...') #2/home/domain.net/public_html/forumdir/newthread.php(273): eval() #3 /home/domain.net/public_html/forumdir/vbseo.php(1440): require('/home/dom...') #4 {main} thrown in /home/domain.net/public_html/forumdir/bitly.php on line 204

LbR 01-27-2010 07:52 PM

The OP me helped me working it out :) thanks man works with charm now

buro9 01-27-2010 08:07 PM

Quote:

Originally Posted by Nordinho (Post 1968312)
Allrighty, the curl error is gone. Now on to the next one ;)

Scary. You are having fun.

In bitly.php where you have these lines:
PHP Code:

 // we expect JSON so decode it
$json = @json_decode($responsetrue); 

Could you echo $response and then return; out of there so that I can see what the hell bitly returned. The JSON from them should be fine, so I want to be sure it's working at all.

Nordinho 01-27-2010 08:33 PM

Quote:

Originally Posted by buro9 (Post 1968329)
Scary. You are having fun.

In bitly.php where you have these lines:
PHP Code:

 // we expect JSON so decode it
$json = @json_decode($responsetrue); 

Could you echo $response and then return; out of there so that I can see what the hell bitly returned. The JSON from them should be fine, so I want to be sure it's working at all.

Lol, well it's a mod that will save me a lot of time, and an error was fixed, so keeping it positive!

Not to sure what to change exactly though. Tried echoing it out. But I'm getting the same error all the time, so I'm echoing out something wrong.

buro9 01-27-2010 08:37 PM

Basically this:
PHP Code:

echo $response;
exit(); 

You need to see what is coming back before the exception gets thrown.

Nordinho 01-27-2010 08:40 PM

Quote:

Originally Posted by buro9 (Post 1968355)
Basically this:
PHP Code:

echo $response;
exit(); 

You need to see what is coming back before the exception gets thrown.

Ah oke,

here we go:

Quote:

HTTP/1.1 200 OK Server: nginx/0.7.42 Date: Wed, 27 Jan 2010 22:39:49 GMT Content-Type: text/html;charset=utf-8 Connection: keep-alive Content-Length: 376 Allow: GET, HEAD, POST Set-Cookie: anonu=psu__ba8fda56-d8f2-4008-9a45-78795aec6c7e---59cd87d95c4bc62d01c0f3740f056d73; Domain=.bit.ly; expires=Wed, 28-Dec-2011 17:39:49 GMT; Path=/; Version=1 Set-Cookie: bsession=e165dfe2-db36-4c65-bde9-3329f63d8df9---7a0a8596aff915c72e69e50dcc22b10a; Domain=.bit.ly; expires=Wed, 28-Dec-2011 17:39:49 GMT; Path=/; Version=1 { "errorCode": 0, "errorMessage": "", "results": { "http://www.nordinho.net/vbull/showthread.php?t=44452": { "hash": "aLLETL", "shortCNAMEUrl": "http://bit.ly/91KLR4", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/91KLR4", "userHash": "91KLR4" } }, "statusCode": "OK" }

buro9 01-27-2010 08:43 PM

Strange... it's working perfectly fine.

What version of PHP are you using?

Nordinho 01-27-2010 08:46 PM

Quote:

Originally Posted by buro9 (Post 1968360)
Strange... it's working perfectly fine.

What version of PHP are you using?

PHP 5.2.9

It does post as well in bit.ly, it seems to fail at connecting with twitter

buro9 01-27-2010 09:01 PM

Quote:

Originally Posted by Nordinho (Post 1968363)
PHP 5.2.9

It does post as well in bit.ly, it seems to fail at connecting with twitter

I don't think it is, it errors in the bit.ly library when it tries to parse the JSON.

The JSON is fine, it's the call to deserialise it that fails.

This: http://php.net/manual/en/function.json-decode.php

I'll have a stab around tomorrow and see if I can figure it out.

Nordinho 01-27-2010 09:05 PM

Allrighty, thanks for the help sofar!

Jesh 01-27-2010 11:11 PM

Getting 500 internal server error, any ideas?

Bouncer222 01-28-2010 02:43 AM

This mod is all great and I love the idea, never thought of it... but..

How exactly is it helping you get visitors to your site from those viewing your twitter page? I mean...all those threads that are relayed to twitter to be posted have no link backs to your actual vbulletin site, do they? Correct me if I'm wrong.

But if it just copies threads/posts and posts it on tweeter without some sort of link back to original thread... then what's the use?

Again, correct me if I'm wrong.
And thanks for the mod!


All times are GMT. The time now is 06:27 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02390 seconds
  • Memory Usage 1,896KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_php_printable
  • (21)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete