Zen Follower
- Join Date:
- Apr 2004
- Posts:
- 173
- Plugin Contributions:
- 0
Twitter Tweets
Just wondering is there is an addon for twitter so that I can broadcast my items from my store. Thanks.
Views: 12,077
Zen Follower
Just wondering is there is an addon for twitter so that I can broadcast my items from my store. Thanks.
Totally Zenned
I have installed a RSS feed on my own site that you can see in the product pages. If you hover over it, there's a Twitter option that you can use to broadcast... It's not Twitter specific, but does do the job.
Alternatively, if you notice my "Add to Kaboodle" button..... I guess it'd be pretty straightforward to have something the same for Twitter.
Zen Follower
Hi, thanks for the reply. Do you know where I can get that? Not sure where it is? Thanks.
Totally Zenned
Zen Follower
Excellent, thanks for the reply. I am looking for a script that will automatically write to my twitter account for my new items updates. Have not found it yet. I am manually doing with tweetdeck.
Anyone have this addon?
Oji-san
I haven't seen an addon myself, but using the twitter API to post tweets is surprisingly easy.
See.
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
Zen Follower
Thank you! I have seen a script (realize I am not a programmer) that does it automatic from your own website. I am not trying to be lazy.... :)....just focusing on adding new items to my site once I get it up & running. But thank you for the info again.
Totally Zenned
Oji-san
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);
}
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);
}
I'd like to try that code myself for my own site if it automatically updates Twitter... Tell me, what file should I place that code into?
Moreover, what exactly will it post to Twitter?
Oji-san
its just a very basic function for wrapping the curl calls necessary to send an update to twitter.
of itself it won't do anything automatically.
The function takes 3 parameters.
$user = your twitter screen name.
$password = your twitter password.
$message = the message you want to send to your twitter timeline.
So somewhere in your code, you would put something like this.
$message = 'Zen Cart Rocks';
$user = 'myTwitterName';
$password = 'myTwitterPassword';
updateStatus($user, $password, $message);
whichever page that you used that on would also have to include the function posted earlier.
The function wasn't particularly meant to be used in live code, just as an example of how easy it is to do.
Totally Zenned
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?
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?
Ah...this would be great! My original question. API? Again, I am not sure. I have seen it done on Twitter and a tiny url is added because most links are too long.
Oji-san
k,
I didn't really want to get into a long discussion about implementation, hoping others might take up the baton. :smile:
However, here's a bit more.
In admin/includes/modules/update_product.php, just before the zen_redirect right at the end of the file, add the code below.
This will send a fairly simple message to your twitter timeline (when a NEW product is added), note also I have taken advantage of the tinyUrl api to encode the product link.
Again a warning. This is not meant to be production code, use at your own risk. !!!!!
You could also take a look at
http://brandontreb.com/the-only-twitter-api-php-class-you-will-ever-need/
if you are wanting to be a bit more adventurous.
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
Hi, Thanks for that code, I was excited about it but unfortunately it doesn't appear to do anything at all.
I uploaded a new product to see if it added it to Twitter and unfortunately, it didn't.
All I done was add this code to the update_product.php before the line zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
I changed the ******** with my Twitter password of course...... Any idea why it's not working? Am I missing a step somewhere?
// BOF twitter feed
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 = 'limelites';
$password = '********';
updateStatus($user, $password, $message);
}
// EOF twitter feed
Zen Follower
Thanks Wilt, it's a start. Again, thanks for taking the time :) Will give it a try.
Oji-san
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.
Zen Follower
Ah once again...thanks Wilt.
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');
<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>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.
<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.
OK, I changed the code as per the lines above but again, the code seems to do nothing at all. Are you having any luck with this **Linux**?
Could it be that I don't usually click "New Product" as I always find it much easier to duplicate an existing product from the same manufacturer and then alter it?
I'll try the "New Product" button and see if that makes a difference. But as for now, the code doesn't work when I copy/duplicate a product.
Oji-san
ummm, yes. The code was written specifically for when you 'add a new product'
Tell staff why this post should be reviewed.