Abraham's oAuth library and examples work pretty much out of the box.
https://github.com/abraham/twitteroauth

If you need any help, please feel free to ask me off the list.

regards
Peter

On Thu, Jan 27, 2011 at 12:59 PM, Mike Jones <[email protected]> wrote:

> I was using the following code to hook to my twitter account but now
> since I was using basic authentication instead of OAuth I am not
> tweeting anymore. Does anyone know of the code of samples that use
> OAuth with cURL/PHP?
>
> <?
>
>
> function make_jmp_url($url,$login,$appkey,$format = 'xml',$version =
> '2.0.1') {
>        //create the URL
>        $jmp = 'http://api.j.mp/shorten?version='.
> $version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.
> $appkey.'&format='.$format;
>
>        //get the url
>        $response = file_get_contents($jmp);
>
>        //parse depending on desired format
>        if(strtolower($format) == 'json')
>        {
>                $json = @json_decode($response,true);
>                return $json['results'][$url]['shortUrl'];
>        }
>        else //xml
>        {
>                $xml = simplexml_load_string($response);
>                return 'http://j.mp/'.$xml- <http://j.mp/%27.$xml->
> >results->nodeKeyVal->hash;
>        }
> }
>
> function tweet($status) {
>
>        $username = 'test';
>        $password = 'test';
>
>        if ($status) {
>        $tweetUrl = 'http://www.twitter.com/statuses/update.xml';
>
>        $curl = curl_init();
>        curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
>        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
>        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
>        curl_setopt($curl, CURLOPT_POST, 1);
>        curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
>        curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
>
>        $result = curl_exec($curl);
>        $resultArray = curl_getinfo($curl);
>
>        if ($resultArray['http_code'] == 200) {
>                $msg += ' and was Tweeted!';
>        }
>
>        curl_close($curl);
>        }
> }
>
>        $tweet = '';
>
>        $longURL = 'http://test.com' . $row->id;
>        $shortURL = make_jmp_url($longURL, 'username', 'apikey', 'json');
>
>        $tweet .= urlencode( $row->title );
>
>        if (strlen($tweet) > 119) {
>                // shorten status update to fit in 140 with URL
>                $tweet = substr($tweet, 0, 116 ) . '...';
>        }
>
>        $tweet .= ' - ';
>        $tweet .= $shortURL;
>
>        tweet($tweet);
>
> ?>
>
> --
> Twitter developer documentation and resources: http://dev.twitter.com/doc
> API updates via Twitter: http://twitter.com/twitterapi
> Issues/Enhancements Tracker:
> http://code.google.com/p/twitter-api/issues/list
> Change your membership to this group:
> http://groups.google.com/group/twitter-development-talk
>



-- 
Peter Denton
Co-Founder, Product Marketing
www.mombo.com
cell: (206) 427-3866
twitter @Mombo_movies
twitter - personal: @petermdenton

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk

Reply via email to