Zen Follower
- Join Date:
- Apr 2004
- Posts:
- 173
- Plugin Contributions:
- 0
Zen Follower
Totally Zenned
Zen Follower
Totally Zenned
Zen Follower
Oji-san
Zen Follower
Totally Zenned
Linux:
I have seen a script (realize I am not a programmer) that does it automatic from your own website.
Oji-san
function updateStatus($user, $password, $message)
{
$url = "https://twitter.com/statuses/update.xml";
$curl = curl_init($url);
$data = array('status'=>$message);
curl_setopt($curl, CURLOPT_USERPWD, $user.':'.$password);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
$result = curl_exec($curl);
}Totally Zenned
wilt:
Hi,
There are a few classes lurking around the internets to interface the twitter api with php. Google is your friend. :smile:
for those wanting some thing quick and dirty I threw this function together, which will post a message to your Twitter timeline.
WARNING; Theres absolutely no sanity checking going on here at all. Use at your own :shocking: risk.
function updateStatus($user, $password, $message) { $url = "https://twitter.com/statuses/update.xml"; $curl = curl_init($url); $data = array('status'=>$message); curl_setopt($curl, CURLOPT_USERPWD, $user.':'.$password); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); $result = curl_exec($curl); }
Oji-san
$message = 'Zen Cart Rocks';
$user = 'myTwitterName';
$password = 'myTwitterPassword';
updateStatus($user, $password, $message);Totally Zenned
Zen Follower
limelites:
I see, so getting back to the OP then, how would you implement such a function and use it to post your new products? So, every time the OP adds a new product to his site, the code kicks in and posts the URL to Twitter with a standard message?
Oji-san
if ($action == 'insert_product')
{
$purl = zen_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id);
$tinyPurl = file_get_contents('http://tinyurl.com/api-create.php?url='.$purl);
function updateStatus($user, $password, $message)
{
$url = "https://twitter.com/statuses/update.xml";
$curl = curl_init($url);
$data = array('status'=>$message);
curl_setopt($curl, CURLOPT_USERPWD, $user.':'.$password);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
$result = @curl_exec($curl);
curl_close($curl);
return $result;
}
$message = STORE_NAME . ' has a new product. ' . $tinyPurl;
$user = '********';
$password = '******';
updateStatus($user, $password, $message);
}Totally Zenned
Zen Follower
Oji-san
updateStatus($user, $password, $message); $result = updateStatus($user, $password, $message);
$messageStack->add_session($result, 'error');<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="messageStackError">
<td class="messageStackError"><img src="images/icons/error.gif" border="0" alt="Error" title=" Error "> <?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Mon Jun 22 19:53:49 +0000 2009</created_at>
<id>2283649261</id>
<text>Zen Cart has a new product. http://tinyurl.com/lxpf9k</text>
<source>web</source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<user>
<id>32979144</id>Zen Follower
Totally Zenned
wilt:
Hi,
I've successfully tried this a number of times.
You're probably going to have to do some debugging. One thing you could try is this.
Replace this line.
updateStatus($user, $password, $message);
with
$result = updateStatus($user, $password, $message); $messageStack->add_session($result, 'error');
Now when you add a new product, you should see a red error bar at the top of the page, containing a lot of unformatted information.
If you 'view source' for that page you should see something like this.
<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="messageStackError"> <td class="messageStackError"><img src="images/icons/error.gif" border="0" alt="Error" title=" Error "> <?xml version="1.0" encoding="UTF-8"?> <status> <created_at>Mon Jun 22 19:53:49 +0000 2009</created_at> <id>2283649261</id> <text>Zen Cart has a new product. http://tinyurl.com/lxpf9k</text> <source>web</source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>32979144</id>
alternatively there might be some error information returned by the twitter api.
If you do not get the error message, then the code does not seem to be executing.
Oji-san
Destination thread ID and reason are required when shown.
Tell staff why this post should be reviewed.
Required for login, security, and core site functionality.
Help us understand how the site is used so we can improve it.
Used for promotion and personalized campaign measurement.