[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

How do I update my twitter account using a datafeed in VBScript?

Asked by VBnewcomer in VB Script, Active Server Pages (ASP), Miscellaneous Networking

Tags: twitter, VBscript, RSS, data feed

I need to take information from a datafeed and automatically update my twitter account. I found an example on the internet in PHP that does the trick but I have no experience with VB script so I was hoping someone could help me convert it so it works within my ASP site.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
<?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'] = 'USERNAME';// Your twitter username
$settings ['twitter-password'] = 'PASSWORD';// Your twitter password
$settings ['feed-url'] ='FEED';//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);
?>
 
Related Solutions
Keywords: How do I update my twitter account usi…
 
Loading Advertisement...
 
[+][-]10/05/09 07:06 AM, ID: 25495324Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/05/09 09:31 AM, ID: 25496802Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/22/09 12:05 PM, ID: 25883420Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625