Change font size
It is currently Wed Dec 19, 2018 12:13 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: Update a twitter feed from a prim.
PostPosted: Sat Dec 13, 2008 8:25 pm 

Joined: Fri Mar 14, 2008 4:29 am
Posts: 17
This system allows you to update a twitter from a prim. The user simply touches the prim, and the first line of chat is sent as a twitter update. The listener stays open for two minutes, and closes as soon as a line of chat is sent. A small tag is appended to the chat line to show where the update originated and from which avatar. The system requires you have a php scripted relay that sends the update to twitter. I have placed a working example of this script in Lbsa Plaza.

PHP Script
Place this code (edit the password and username strings) into a file named myRelay.php for example. Place the file on a php enabled webserver. You will also require the php curl module. On debian installations this is simply 'sudo apt-get install php5-curl', after installation you will need to restart apache2 to enable the module.
{L_CODE}:
<?php
// ---------------------------------------- */
// Monk Zymurgy - Quick'n'Dirty twitter relay
// Dec 11 2008
// ---------------------------------------- */

// A simple function using Curl to post (GET) to Twitter
// Kosso : March 14 2007

function postToTwitter($username,$password,$message){
    $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);

    $result = curl_exec($ch);
    // Look at the returned header
    $resultArray = curl_getinfo($ch);
    curl_close($ch);

    if($resultArray['http_code'] == "0"){
         $twitter_status='Your message has been sended! http://twitter.com/'.$username.' to view the feed.';
    }
    else {
         $twitter_status="Error posting to Twitter.".$resultArray['http_code'];
    }
    return $twitter_status;
}

// here is where you hard code your twitter username and password

$twitter_username       ='yourname';
$twitter_psw            ='yourpass';

// if you like to make a relay for many twitter feeds that is not-so-safe
// use these lines instead :
// $twitter_username       =$_GET['twitter_user'];
// $twitter_psw            =$_GET['twitter_pass'];

$output_txt='no message data..please try again.';

if(isset($_GET['twitter_msg'])){
        $twitter_message=$_GET['twitter_msg'];
        if(strlen($twitter_message)<1){
            $output_txt='oops..no message text..please try again.';
        }
        else {
            $output_txt=postToTwitter($twitter_username, $twitter_psw, $twitter_message);
        }
}
echo $output_txt;
?>

LSL Script
Place this script into any prim, or linked-set. Edit the script to point to your relay, and change the location details. Also edit the msg variable, as this is the message used to send an 'i am online' update to twitter
{L_CODE}:
// Monk Zymurgy - Twitter sender prim
// 11 Dec 2008

//Edit these lines to suit your set-up
string url = "http://URL_to_your_relay/twitterRelay.php";
string region = "Your_Region";
string grid = "Your_Grid";
string msg = "TwitterBox is ONLINE. Situated in Your_Grid in the 'Your_Region' region.";

key http_request_id;
integer inuse;
integer listener;

closeListener() {
    llSetTimerEvent(.0);
    llListenRemove(listener);
    inuse = FALSE;
    llSetText("Touch Me!\nTo leave a twitter.",<0.2,.5,1.0>,.9);
}

twitter(string message) {
    http_request_id = llHTTPRequest(url+"?twitter_msg="+llEscapeURL(message),[],"");
return;
}
   

default
{
    state_entry() {
        llSay(0,"Web link is ONLINE...[OK]");
        closeListener();
        twitter(msg);       
    }
   
    touch_start(integer num) {
        if(inuse == FALSE) {
            inuse = TRUE;
            llSetText(llDetectedName(0)+" is Twittering..",<.2,1.0,.2>,.9);
            llSay(0,"Please speak your twitter "+llDetectedName(0)+"! The listener will stay open for 2 minutes.");
            listener = llListen(0,"",llDetectedKey(0),"");
            llSetTimerEvent(120.0);
        }
    }
   
    listen(integer chan, string name, key id, string msg) {
        closeListener();
        llSay(0,"Sending twitter...");
        twitter(msg+" >> sent by "+(name)+" in ("+grid+"/"+region+") <<");
    }
   
    timer() {
        closeListener();
        llSay(0,"Listener has timed out! Please touch again.");
    }
   
    http_response(key request_id, integer status, list metadata, string body) {
        if (request_id == http_request_id) llSay(0,body); else llSay(0,"Error! - "+(string)status+" - "+body);
    }
}


Top
 Profile  
 
 Post subject: Re: Update a twitter feed from a prim.
PostPosted: Thu May 14, 2009 11:29 pm 

Joined: Wed May 06, 2009 7:26 am
Posts: 28
Just wondering how would i send the avatars UUID code?

I want each user to be able to use the same twitter box.


Top
 Profile  
 
 Post subject: Re: Update a twitter feed from a prim.
PostPosted: Tue May 19, 2009 2:53 pm 

Joined: Mon Jan 12, 2009 5:03 pm
Posts: 24
{L_QUOTE}:
PHP Script
Place this code (edit the password and username strings) into a file named myRelay.php for example. Place the file on a php enabled webserver. You will also require the php curl module. On debian installations this is simply 'sudo apt-get install php5-curl', after installation you will need to restart apache2 to enable the module.


:shock:

thank you for the inspiration. i had to rewrite the php script because currently it throws an .417 error code.
Twitter changed some things and most php curl versions have the problem with getting the header right. i had to
add

{L_CODE}:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));


that throws another error in the chat window ... the .200 error .. which is basically not an error
because it means OK ! .. so i changed your error checks to this

{L_CODE}:

    if($resultArray['http_code'] == "0"){
         $twitter_status='Your message has been sent! http://twitter.com/'.$username.' to view the feed.';
    }
    if($resultArray['http_code'] == "200"){
     $twitter_status='Your message has been sent with .200 ! http://twitter.com/'.$username.' to view the feed.';
    }
    else {
         $twitter_status="Error posting to Twitter.".$resultArray['http_code'];
    }
    return $twitter_status;
}



which is perfectly ok and means great Job :-)

so here the full commented php part for all of you to use ..

{L_CODE}:
<?php
// ---------------------------------------- */
// heavyly commented by Wordfromthe Wise
// May 2009 to use in the OSGRID
// credit where credit is due
// so i leave the original Header intact
// ---------------------------------------- */
// Monk Zymurgy - Quick'n'Dirty twitter relay
// Dec 11 2008
// ---------------------------------------- */
// A simple function using Curl to post (GET) to Twitter
// original by Kosso : March 14 2007
// or Monk Zymurgy Dec 11 2008
// ---------------------------------------- */

function postToTwitter($username,$password,$message){
    $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
//   curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0(compatible; MSIE 5.0;Windows 98; DigExt)");
    curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0 );
//  CURLOPT_HEADER 0 = this somehow shows your twitter profile when combined with  return $result;
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
//  CURLOPT_HTTPHEADER is the one responsible for a .417 error
//
    $result = curl_exec($ch);
    // Look at the returned header
    $resultArray = curl_getinfo($ch);
    curl_close($ch);
//
    if($resultArray['http_code'] == "0"){
         $twitter_status='Your message has been sent! http://twitter.com/'.$username.' to view the feed.';
    }
    if($resultArray['http_code'] == "200"){
     $twitter_status='Your message has been sent with .200 ! http://twitter.com/'.$username.' to view the feed.';
//        return $result;    //   combined with CURLOPT_HEADER, 0 to show your unformatted Twitter Profile
    }
    else {
         $twitter_status="Error posting to Twitter.".$resultArray['http_code'];
    }
    return $twitter_status;
}

// here is where you hard code your twitter username and password

$twitter_username       ='donotevapostyour';
$twitter_psw            ='passwordshere';

// if you like to make a relay for many twitter feeds that is not-so-safe
// use these lines instead :
// $twitter_username       =$_GET['twitter_user'];
// $twitter_psw            =$_GET['twitter_pass'];

$output_txt='no message data..please try again.';

if(isset($_GET['twitter_msg'])){
        $twitter_message=$_GET['twitter_msg'];
        if(strlen($twitter_message)<1){
            $output_txt='oops..no message text..please try again.';
        }
        else {
            $output_txt=postToTwitter($twitter_username, $twitter_psw, $twitter_message);
        }
}
echo $output_txt;
?>


now .. its only a matter of time if all islands are tweeting .. :D
and mayby if somebody has some ideas for the .lsl part of it ...
:ugeek: how about sensor sensed visitor tweet boxes ..
or :roll: let your sim say hello when she rezzed after a restart ..
:oops: mayby with an on_REZ ??

greetings and have fun with teh Scriptz ...

WordfromtheWise ..

:arrow: PS.. looking for good examples of how to talk to, and read from a 8-) database ...


Top
 Profile  
 
 Post subject: Re: Update a twitter feed from a prim.
PostPosted: Tue May 19, 2009 6:03 pm 
Site Admin
User avatar

Joined: Sat Feb 02, 2008 5:27 pm
Posts: 843
nice always good to see people keeping scripts alive, i think we'll probably find that over time some of these scripts will stop working and require updates... thanks for sharing.

Neb :ugeek:


Top
 Profile  
 
 Post subject: Re: Update a twitter feed from a prim.
PostPosted: Mon Dec 27, 2010 4:11 pm 

Joined: Mon Dec 27, 2010 4:10 pm
Posts: 1
I just stumbled on this, so I don't have code, but it needs to be updated with twitter's new OAuth requirement, user/pass combos won't work anymore.


Top
 Profile  
 
 Post subject: Re: Update a twitter feed from a prim.
PostPosted: Sun Feb 06, 2011 9:06 am 

Joined: Sun Feb 06, 2011 9:04 am
Posts: 1
this info could help, but i cant do it to less knowledge

http://www.1stwebdesigner.com/tutorials ... oauth-php/

kan somone have an eye on it? ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net