Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #2 on: Jul 18, 2009, 11:00:25 pm »
The settings is set... no changes... though I have tried 'hard coding' my username and password into the URL api ... that didn't work,.
Here's the code
Code:
<?php /* * Script that posts multiple RSS feeds to twitter * * Use this with crontab (it works with CLI too) * to post your feed's content to twitter * * A tutorial by: * http://www.webdigity.com/ * */
$settings ['twitter-username'] = 'xxxxx';// Your twitter username $settings ['twitter-password'] = 'xxxxx';// Your twitter password $settings ['feed-url'] ='xxxxxxl';//The url of the feed we are going to post to twitter
set_time_limit(0);//We need this because otherwise php will probably time out //Let's see if we have the curl library if (!extension_loaded('curl') && !dl('curl.' . (stristr(php_OS, 'WIN')?'dll':'so'))) die( 'Curl is not loaded' ); //Now we need a file to log the last entry so we wont post it again $file = dirname(__FILE__) . '/feed.log.txt'; if ( !file_exists( $file ) ){ $fp = @fopen( $file, 'w'); if (! $fp ) die( 'Could not write to log file. Check your permissions.' ); fclose( $fp ); } else if ( !is_writable( $file ) ) die( 'Could not write to log file. Check your permissions.' ); //Fetch the RSS feed $ch = curl_init( $settings['feed-url'] ); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $feed = simplexml_load_string ( curl_exec($ch) ); curl_close($ch); //Parse the feed $messages = array();//Here we will store all the messages that we are going to post to twitter foreach( $feed->channel->item as $item ){ $title = $item->title; // If you want to fetch the description instead use $item->description $url = $item->link; //Have we already posted that? if ( $url == file_get_contents($file) )break; //Now do the actual posting. //First we need to shorten the url $ch = curl_init( 'http://twt.gs/?url='.$url.'&user='.$settings['twitter-username'].'&pass='.$settings['twitter-password'] ); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $shortURL = curl_exec($ch); $resp = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ( $resp != '200' ) die('Problem with the url shortening service. Check back later. Error: '.$shortURL); //Now Calculate the twit message $cnt = 140 - strlen($shortURL) - 1; $messages [] = strlen($title) <= $cnt ? $title . ' ' . $shortURL : substr($title,0,$cnt-3).'... '.$shortURL; $lastURL = empty($lastURL) ? $url : $lastURL; } //Post to twitter while( $message = array_pop($messages) ){ $ch = curl_init('http://twitter.com/statuses/update.xml'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'status='.urlencode($message)); curl_setopt($ch, CURLOPT_USERPWD, $settings['twitter-username'].':'.$settings['twitter-password']);
$response = curl_exec($ch); $resp = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ( $resp != '200' ) die('Problem with twitter. We should try later. Twitter reported: '.$response); else sleep(5);//Sleep 5 seconds before the next update } $fp = fopen($file, 'w'); fwrite($fp, $lastURL); fclose($fp); ?>
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #3 on: Jul 18, 2009, 11:02:18 pm »
I also noticed that if I remove this section the code will actually execute... well sort off... it will post the entire feed to twitter, but with no URLs. It also does not use the log properly, in that if I run the script again it will repost the entire feed. Thanks for your help.
Code:
//First we need to shorten the url $ch = curl_init( 'http://twt.gs/?url='.$url.'&user='.$settings['twitter-username'].'&pass='.$settings['twitter-password'] ); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $shortURL = curl_exec($ch); $resp = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ( $resp != '200' ) die('Problem with the url shortening service. Check back later. Error: '.$shortURL);
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #4 on: Jul 22, 2009, 01:23:35 am »
help pls?
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #5 on: Jul 24, 2009, 02:14:31 pm »
anyone?
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #6 on: Jul 29, 2009, 02:20:50 pm »
can anyone help?
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #7 on: Jul 29, 2009, 05:17:10 pm »
Ugh - I'm reading through the code - not really noticing anything out of the ordinary - Did you change anything??
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #8 on: Jul 31, 2009, 04:01:58 pm »
Nope... nothing changed other than username etc... is anyone using this code successfully? Maybe twitter changed something?
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #9 on: Jul 31, 2009, 04:12:37 pm »
/statuses/update.xml' Statuses? Typo maybe? That's what I would back over - ensure that all of your spelling is correct for linkage - usually that's what I make mistakes on. Don't pull your hair out over it - it's most likely something very simple you've overlooked
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
It has to be replaced with the one I gave you otherwise tinyurl will put your username and password at the end of all your urls.. lol.. Tinyurl does not need your username and password like the other url shortening company did.
Also create a blank feed.log.txt and upload to same folder that you have the rss to twitter script and chmod on log file to 777. It should work then.
« Last Edit: Sep 18, 2009, 08:20:29 am by raymond4000 »
Nikolas' Servant's Servant
Posts: 29
190 credits Members referred : 0
« Reply #18 on: Sep 18, 2009, 08:31:37 pm »
raymond - I appreciate you willing to work with me on this so much! We have made good progress so far... it's posting to twitter, and loading the the last url into the feed.log.txt file... however ON twitter, there is no link, it still says "ERROR" in place of a link. My code is below, thank you for your help.
$response = curl_exec($ch); $resp = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ( $resp != '200' ) die('Problem with twitter. We should try later. Twitter reported: '.$response); else sleep(5);//Sleep 5 seconds before the next update } $fp = fopen($file, 'w'); fwrite($fp, $lastURL); fclose($fp); ?>
Chicken-run Manager
Posts: 9
54 credits Members referred : 0
« Reply #19 on: Sep 18, 2009, 08:39:06 pm »
Thats odd.... Why don't you try a different rss feed then and see if it still does that. I am not having that issue. My title comes up and then the url....
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=8948