+ Reply to Thread
Results 1 to 5 of 5

Thread: Looking for simple and basic twitter plugin

  1. #1
    ryanmaelhorn77 Guest

    Looking for simple and basic twitter plugin

    Looking for a script/plugin/whatever, that can tweet the contents of a txt file I have on my x10 site if it has changed from the last tweet. the txt file will be updated at irregular times by another program running on my pc. Just need something to check it at set times (every 12 hours perhaps?) see if it has changed, and tweet it out if it has.

    That's it, no need to recieve msgs from twitter or anything else, simply check and post.

    ???

  2. #2
    worldwise001's Avatar
    worldwise001 is offline x10Hosting Member worldwise001 is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Carbondale, IL
    Posts
    57

    Re: Looking for simple and basic twitter plugin

    Here's something:

    PHP Code:
    <?php

    $username 
    'username';
    $password 'password';
    $filename '/path/to/textfile';
    $script_home '/path/to/script/dir';
    $desc 'file has changed:';
    $show_contents true;

    // Don't change anything down here

    function twitter_update($username$password$message) {
        
    $c curl_init();

        
    $message str_replace(' ''+'$message);
        
    $message str_replace("\n"'+'$message);

        
    curl_setopt($cCURLOPT_TRANSFERTEXTtrue);
        
    curl_setopt($cCURLOPT_URL'http://twitter.com/statuses/update.json');
        
    curl_setopt($cCURLOPT_USERPWD$username.':'.$password);
        
    curl_setopt($cCURLOPT_POST1);
        
    curl_setopt($cCURLOPT_POSTFIELDS'status='.$message);
        
        
    curl_exec($c);
        
    curl_close($c);
    }

    if (!
    file_exists($script_home.'/datafile') || (md5_file($script_home.'/datafile') != md5_file($filename))) {
        if (!
    copy($filename$script_home.'/datafile')) {
            die(
    'Unable to copy file for local storage; '.$script_home.' needs world-writeable permissions');
        }
        
    $data $desc;
            if (
    $show_contents) {
                    
    $readlen 140 strlen($desc) - 1;
            
    $rsrc fopen($script_home.'/datafile''r');
            if (
    $rsrc === false) die('Unable to open file; check permissions?');
            echo 
    'reading';
            
    $innards fread($rsrc$readlen+1);
            if (
    strlen($innards) > $readlen) {
                
    $innards substr($innards0, -4);
                
    $innards .= '...';
            }
            
    fclose($rsrc);
            
    $data .= ' '.$innards;
            echo 
    $data;
            }
        
    twitter_update($username$password$data);
    }

    ?>
    Explanation of variables:

    $username - Twitter username
    $password - Twitter password
    $filename - full path to text file (e.g. /home/worldwise001/mytext
    $script_home - full path to directory with script (e.g. /home/worldwise001/myscript)
    $desc - message text to display on twitter
    $show_contents - show the (partial) contents of the file (if true)

    Directions:
    1. Copy and modify the contents of the above code snippet into a php file (e.g. tweet.php)
    2. Upload the file to the script directory, e.g. to /home/worldwise001/myscript/tweet.php
    3. chmod the script directory to 0777
    4. Add a cron job in your cPanel to run the script, e.g.:
      Code:
      php -f /home/worldwise001/myscript/tweet.php

    Hope this helps.


  3. #3
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Looking for simple and basic twitter plugin

    There's going to be a little problem with that -- Twitter has dropped basic authentication for the API (at the end of July, in fact) and now requires oAuth. That means you now need to make an authentication token request to your oAuth provider, then provide the token in a separate request to Twitter in exchange for an authorization token that you can then provide as your credentials for the status update. No more simple user/password in the request.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  4. #4
    worldwise001's Avatar
    worldwise001 is offline x10Hosting Member worldwise001 is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Carbondale, IL
    Posts
    57

    Re: Looking for simple and basic twitter plugin

    Hmm... are you sure about that? It worked for me last night when I tested it (I wrote this from scratch).


  5. #5
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Looking for simple and basic twitter plugin

    Support for basic authentication was set to be disabled on the 16th of this month, so it seems odd that it is still working. Either way though, it is a dead method for any current development.

+ Reply to Thread

Similar Threads

  1. Does Anybody Use Twitter?
    By gman11234 in forum Off Topic
    Replies: 21
    Last Post: 10-20-2009, 03:15 PM
  2. Twitter
    By Bryon in forum Off Topic
    Replies: 13
    Last Post: 06-23-2009, 02:02 PM
  3. Anyone using Twitter?
    By dWhite in forum Off Topic
    Replies: 20
    Last Post: 02-22-2009, 07:30 PM
  4. Anyone on Twitter?
    By KowKing in forum Off Topic
    Replies: 6
    Last Post: 05-01-2007, 08:12 AM
  5. A simple Visual Basic Login Form
    By Zenax in forum Tutorials
    Replies: 0
    Last Post: 03-13-2007, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers