Thread: Twitter Tweets

Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 60
  1. #11
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,929
    Plugin Contributions
    4

    Default 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.

    Code:
    $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.

  2. #12
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default 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?

  3. #13
    Join Date
    Apr 2004
    Posts
    191
    Plugin Contributions
    0

    Default Re: Twitter Tweets

    Quote Originally Posted by limelites View Post
    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.

  4. #14
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,929
    Plugin Contributions
    4

    Default Re: Twitter Tweets

    k,

    I didn't really want to get into a long discussion about implementation, hoping others might take up the baton.

    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-twit...ill-ever-need/

    if you are wanting to be a bit more adventurous.


    Code:
        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);
        }

  5. #15
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default 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 Code:
    // 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($curlCURLOPT_USERPWD$user.':'.$password);
            
    curl_setopt($curlCURLOPT_POST1);
            
    curl_setopt($curlCURLOPT_POSTFIELDS$data);
            
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);
            
    curl_setopt($curlCURLOPT_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 
    Last edited by limelites; 22 Jun 2009 at 07:01 PM.

  6. #16
    Join Date
    Apr 2004
    Posts
    191
    Plugin Contributions
    0

    Default Re: Twitter Tweets

    Thanks Wilt, it's a start. Again, thanks for taking the time :) Will give it a try.

  7. #17
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,929
    Plugin Contributions
    4

    Default 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.

    Code:
          updateStatus($user, $password, $message);
    with
    Code:
          $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.

    Code:
    <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 ">&nbsp;<?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.

  8. #18
    Join Date
    Apr 2004
    Posts
    191
    Plugin Contributions
    0

    Default Re: Twitter Tweets

    Ah once again...thanks Wilt.

  9. #19
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default Re: Twitter Tweets

    Quote Originally Posted by wilt View Post
    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.

    Code:
          updateStatus($user, $password, $message);
    with
    Code:
          $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.

    Code:
    <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 ">&nbsp;<?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.

  10. #20
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,929
    Plugin Contributions
    4

    Default Re: Twitter Tweets

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

 

 
Page 2 of 6 FirstFirst 1234 ... LastLast

Similar Threads

  1. v151 Twitter Feed
    By DigiBooks in forum General Questions
    Replies: 1
    Last Post: 6 May 2015, 02:03 AM
  2. Twitter sidebox
    By karenkte in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 29 Apr 2015, 05:25 PM
  3. v151 Twitter - Tweets not showing
    By karenkte in forum General Questions
    Replies: 1
    Last Post: 8 Mar 2013, 11:49 AM
  4. Twitter
    By irishshopper in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 11 Jul 2010, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg