Twitter Tweets

Locked
Results 1 to 20 of 60
This thread is locked. New replies are disabled.
20 Jun 2009, 16:11
#1
linux avatar

linux

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.
20 Jun 2009, 16:17
#2
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Twitter Tweets

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.
20 Jun 2009, 16:53
#3
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

Hi, thanks for the reply. Do you know where I can get that? Not sure where it is? Thanks.
21 Jun 2009, 16:56
#5
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

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?
21 Jun 2009, 19:23
#7
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

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.
22 Jun 2009, 01:34
#8
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Twitter Tweets

Linux:

I have seen a script (realize I am not a programmer) that does it automatic from your own website.


Would you please post a link to the script? I'd like to check it out!
22 Jun 2009, 13:55
#9
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Posts:
1,783
Plugin Contributions:
3

Re: Twitter Tweets

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);
}
22 Jun 2009, 14:08
#10
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Twitter Tweets

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?
22 Jun 2009, 14:17
#11
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Posts:
1,783
Plugin Contributions:
3

Re: Twitter Tweets

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.
22 Jun 2009, 14:27
#12
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Twitter Tweets

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?
22 Jun 2009, 15:28
#13
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

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.
22 Jun 2009, 17:27
#14
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Posts:
1,783
Plugin Contributions:
3

Re: Twitter Tweets

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);
    }
22 Jun 2009, 17:58
#15
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Twitter Tweets

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?

[PHP]// 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[/PHP]
22 Jun 2009, 17:59
#16
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

Thanks Wilt, it's a start. Again, thanks for taking the time :) Will give it a try.
22 Jun 2009, 20:00
#17
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Posts:
1,783
Plugin Contributions:
3

Re: Twitter Tweets

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.
22 Jun 2009, 22:23
#18
linux avatar

linux

Zen Follower

Join Date:
Apr 2004
Posts:
173
Plugin Contributions:
0

Re: Twitter Tweets

Ah once again...thanks Wilt.
23 Jun 2009, 07:34
#19
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Twitter Tweets

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.


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.
23 Jun 2009, 07:44
#20
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Posts:
1,783
Plugin Contributions:
3

Re: Twitter Tweets

ummm, yes. The code was written specifically for when you 'add a new product'