Jump to content

Want a Pro PHP Coder to Integrate OAUTH for My Twitter App

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
jss4ever

jss4ever

    Newbie

  • Members
  • PipPip
  • 10 posts
Hey All


Someone Referred me To This Awesome Forum

Im Still a Newbie

and I Need Your Help With Integrating Twitter OAUTH For my Simple Twitter App Website

TweetWonder . com

Here is The Code


<?php

include ('../config.php');

?><?php


class twitter {

    

    private $user;

    private $pass;

    private $ch;

    private $twitterHost = "http://twitter.com/";

    

    public function __construct() {

        $this->user = trim($_POST['user']);

        $this->pass = trim($_POST['pass']);

        

        /* Create and setup  the curl Session */

        $this->ch = curl_init();

    

        curl_setopt($this->ch, CURLOPT_VERBOSE, 1);

        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($this->ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");

        curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

        curl_setopt($this->ch, CURLOPT_POST, 1);

    }

    

    public function __destruct() {

        /*clean Up */

        curl_close($this->ch);

    }


    public function setStatus($stat) {

    

        if(strlen($stat) < 1)

            return false; 

        

        /*Set the host information for the curl session */

        $this->twitterHost .= "statuses/update.xml";


        curl_setopt($this->ch, CURLOPT_URL, $this->twitterHost);


        curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query(array("status" => stripslashes(urldecode($stat)))));


        

        /* Execute and get the http code to see if it was succesfull or not*/

        $result = curl_exec($this->ch);

        $resultArray = curl_getinfo($this->ch);

                

        if ($resultArray['http_code'] == 200) ;

            return true;

            

        return false;

    }

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">


<head>

<title><?php echo "$name";?></title>

<meta content="application/xhtml+xml; charset=iso-8859-1" http-equiv="content-type" />

<meta content="" name="description" />

<meta content="" name="keywords" />

<link href="bluestyle210.css" media="screen,projection" rel="stylesheet" type="text/css" />

</head>


<body>


<div id="container">

	<div id="outcome">

		<?php




$curTwitter = new twitter();

        

if (isset($_POST['submit'])) {


    $twitter_status = $_POST['twitter_stat'];

    

    if (strlen($twitter_status) > 0) {


        if( $curTwitter->setStatus($twitter_status) == true)

            echo "<p>Updated Succesfully</p>";

        else

            echo "<p>Twitter is unavailable at this time</p>";

    } else

        echo "<p>Error: I won't send blank messages!</p>";



}


?></div>

	<div id="main">

		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

			<p>Username & Password:</p>

			<input id="user" class="user" name="user" type="text">

			<input id="pass" class="pass" name="pass" type="password">

			<p>140 Character Message:</p>

			<textarea id="twitter_stat" maxlength="140" name="twitter_stat" type="text"></textarea>

			<input id="submit" name="submit" type="submit" value="Send" /><br />

		</form>

		<div class="clearer" style="height: 12px">

			<a href="http://<?php echo "$url";?>"><?php echo "$site";?></a>

</div>

	</div>

</div>


</body>


</html>




If Anyone Can Please PM Me or POST Here

I Will Give Away An Awesome Web design + CSS/XHTML Coded from my Services

jssnetwork . com

I Will PM You With The Information Such as
Consumer key
Consumer secret
Request token URL
Access token URL
Authorize URL

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Have you thought about getting a pre-made Twitter OAuth class? jmathai's twitter-async at master - GitHub

Some other examples here: Twitter API Wiki / OAuth Examples