MyBB Community Forums

Full Version: Need a little help finishing off Tweet to Twitter plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I am trying to create a plugin to tweet new threads to Twitter. I found a tutotial on mybbsource, that did not work: http://mybbsource.com/archive/index.php/...-3745.html

I then found another to tweet calendar events from mybb to Twitter, and that didn't work either: http://valadilene.org/2010/02/09/how-to-...ts-on-mybb

So, I took what was applicable and rewrote it, but I don't quite have it right. I know that it should be simple and there's not much code to it, but I'm just not experienced enough to get the querie right and am not quite sure on how to properly configure the fields to send to Twitter.

I get several errors after activating the plugin and creating a thread, and it does not tweet the thread to Twitter, surprise-surprise.

There are 3 errors displayed after posting a thread, including:

[PHP] error->Handler
inc/class_plugins.php Line 101 call_user_func_array
newthread.php Line 431 Plugin System ->run_hooks

Anyone that can help finish this off is welcome to take credit for it.

I am also using the Google SEO plugin available here.

Here is what I have now:
<?php
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("newthread_do_newthread_end", "twitterfeed");

function testplugin_info()
{
	return array(
		"name"			=> "Twitterfeed",
		"description"	=> "Tweed new threads to Twitter!",
		"website"		=> "",
		"author"		=> "",
		"authorsite"	=> "",
		"version"		=> "1.1",
		"guid"			=> "",
		"compatibility" => "1*",
	);
}

function twitterfeed_activate()
{
}

function twitterfeed_deactivate()
{
}

function twitterfeed_addthread()
{
        global $details, $mybb, $db;

        // gets thread data from the db
        $q=$db->simple_select('threads','username, subject, dateline, fid, tid',array('limit'=>1));
        $thread=$db->fetch_array($q);

        // include twitter class
        require_once('class.twitter.php');
        require_once('twitterOAuth/twitterOAuth.php');
        require_once('twitterOAuth/OAuth.php');

        // get URL
        $url($mybb->settings['bburl']."/newthread.php?action=fid");

        // send twitter status
        $tw=new twitter();
        $tw->username=myusername;
        $tw->password=mypassword;
        $tw->update("[".my_date('d M',$thread['subject'])."] {$thread['username']} {$url}");
}

?>

And I am attaching the Twitter class file I have. I am also using the twitterOAuth library, which is the same library used for the Twitter Login plugin.
Change

$plugins->add_hook("newthread_do_newthread_end", "twitterfeed");

To

$plugins->add_hook("newthread_do_newthread_end", "twitterfeed_addthread");
Well I think that helped, but now it doesn't like the SQL querie and generates this error:

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1054 - Unknown column 'Array' in 'where clause'
Query:
SELECT username, subject, dateline, fid, tid FROM threads WHERE Array
I think this is closer to what you are trying to do..
Find
function twitterfeed_addthread()
{
        global $details, $mybb, $db;

        // gets thread data from the db
        $q=$db->simple_select('threads','username, subject, dateline, fid, tid',array('limit'=>1));
        $thread=$db->fetch_array($q);

        // include twitter class
        require_once('class.twitter.php');
        require_once('twitterOAuth/twitterOAuth.php');
        require_once('twitterOAuth/OAuth.php');

        // get URL
        $url($mybb->settings['bburl']."/newthread.php?action=fid");

        // send twitter status
        $tw=new twitter();
        $tw->username=myusername;
        $tw->password=mypassword;
        $tw->update("[".my_date('d M',$thread['subject'])."] {$thread['username']} {$url}");
}
Change to
function twitterfeed_addthread()
{
        global $new_thread, $mybb, $tid, $thread_info;

        // include twitter class
        require_once('class.twitter.php');
        require_once('twitterOAuth/twitterOAuth.php');
        require_once('twitterOAuth/OAuth.php');

        // get URL
        $url = get_thread_link($tid);

        // send twitter status
        $tw=new twitter();
        $tw->username=myusername;
        $tw->password=mypassword;
        $tw->update("[".my_date('d M',$thread_info['dateline'])."]" . $new_thread['subject'] . " " . $new_thread['username']  . " " . $url);
}
Ok, now we get past the last error, but it doesn't seem to like the login and generates this eror:

Fatal error: Cannot access private property Twitter::$username in /home/truth/public_html/inc/plugins/testplugin.php on line 45

I am using my actual Twitter username and password in the login fields.

Any thoughts?

I also concluded that the oauth libraries are not required, since we're really not trying to use an API and request information back, and can be removed. And, doing so does not affect the error, excpept to place it on line 43 instead of 45.
Check on how you have to pass the username and password to the twitter either in a set method or a constructor.
I was just looking at that in the class.twitterr.php. It's a constructer:

// class methods
/**
* Default constructor
*
* @return void
* @param string[optional] $username The username for an authenticating user
* @param string[optional] $password The password for an authenticating user
*/


public function __construct($username = null, $password = null)
{
if($username !== null) $this->setUsername($username);
if($password !== null) $this->setPassword($password);
}
So change
$tw=new twitter('myusername','mypassword');

And remove
$tw->username=myusername;
$tw->password=mypassword;
Man you are really helping here. Now it's at the last line and it doesn't like update as a method. I am looking through the class.twitter.php again to see what I can find. But if yu have a quick answer, I believe we've got it. Here's the error:

Fatal error: Call to undefined method Twitter::update() in /home/truth/public_html/inc/plugins/testplugin.php on line 46
What functions are in the Twitter file?
like function setPassword
Pages: 1 2 3