Thread: Miscellaneous Hacks - vBulletin to Twitter, live tweets of new threads
View Single Post
  #594  
Old 06-18-2012, 12:51 PM
cuco88 cuco88 is offline
 
Join Date: Jun 2012
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried this with my 4.2.0-board. It didn't work, the bit.ly-thing threw out errors. After fixing that the twitter-thing threw out other and more complicated errors. I tried to fix it and I got it working. But many changes were needed. I try to tell you:

At first, don't use the attached bitly.php. Use the linked one in the first posting. Or take this link:
http://classes.verkoyen.eu/bitly
unzip it, place it in the forum-root

Second: the twitter-API only accepts oAuth now, no basic username/password authentication anymore. So you have to use the new twitter.php. Don't use the one attached to the first posting. And don't use the one linked in the first posting. Use this one instead: http://classes.verkoyen.eu/twitter_oauth
unzip it. Don't place it in the forum root now! We have to edit it!

Now you have to get a legacy-API-key from bit.ly: https://bitly.com/a/settings/advanced
And you need oAuth-data from twitter. Use this link: https://dev.twitter.com/ then click on "my applications" in the menu on the upper right. Click on "create new application" and enter your data. (you don't need to enter a callback-url) Then your app is created. Click on "settings" and then switch to "Read, Write and Access direct messages". Update application settings. Go back on the "details"-tab and click on "create my access-token". Go to tab "oAuth tool" You will see four keys now. You need all of them. Open your twitter.php, search for "private $oAuthToken = ' ';" Place the "Access token" here. Then search for "private $oAuthTokenSecret = ' ';" Place your "Aceess token secret" between the ' ' here. Now save the file and upload it to your forum root. The other two codes (consumer key, consumer secret) are needed in the plugin-script, see below.

Go to plugin-manager and create a new plugin:
vBulletin
newthread_post_complete
Tweet to Twitter

Now use the following code
If you want to exclude some forums, edit this line:
$excludedForums = array(1, 2);
and place the forum-ids between the brackets. use array() if you don't want to exclude any forums.

this line:
$shortUrl = 'http://yourURLhere.com/showthread.php?t='.$newpost[threadid];
change "YourURLhere.com" to your forum-URL.

In this line:
$bitly = new Bitly('username', 'API_key');
you have to put in your bit.ly-username and the generated API-key.

And in this line:
$twitter = new Twitter('consumer-key','consumer-secret');
you have to put in the consumer-key and the consumer-secret from the twitter o-auth-tool.


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(12);

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

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

    if (
$useBitly) {
      
// http://classes.verkoyen.eu/bitly
      
require_once 'bitly.php';
      
$bitly = new Bitly('username''API_key');
      
$result_bit = array();
      
$result_bit $bitly->shorten($shortUrl);
      
$shortUrl $result_bit['url'];
    }

    
$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('consumer-key','consumer-secret');
    
$twitter->statusesUpdate($tweet);

Save and activate it. This worked for me :-) No curl-erros anymore, no "unauthorized access" errors anymore, no .... errors, just working
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02043 seconds
  • Memory Usage 1,795KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete