Forums

[Plugin: Twitter Tools] URL not made tiny (11 posts)

  1. spidermann
    Member
    Posted 7 months ago #

    Up until April Fool's day this plugin has been working perfectly. Each time a new blog post was made it would send to the Twitter account and the URL was made into a tinyURL.

    Now, it won't tinyURL for some reason. It still posts to Twitter, just no shortening of the URL. Anyone else have this issue or know of a fix? I like the plugin as it is a small foot print and was working perfect until this.

  2. dnorth
    Member
    Posted 7 months ago #

    I am having the same problem. Wish someone knew the answer.

  3. dnorth
    Member
    Posted 7 months ago #

    I was reading the documentation (I know that is unusual) for Twitter Tools and it says it does not do any URL shortening, but let Twitter do it. So maybe that function is not working in Twitter any more.

    Twitter tools readme file has info about adding a filter and a function to do the URL shortening.

    It says:

    Twitter Tools also provides a filter on the URL sent to Twitter so that you can run it through an URL-shortening service if you like.

    tweet_blog_post_url

    Your plugin function will receive the URL as the first parameter.

    Example psuedo-code:

    function my_short_url($long_url) { // do something here - return the shortened URL }
    add_filter('tweet_blog_post_url', 'my_short_url')

    I am not sure were to put this code or where to get a urlshortening function. If anyone knows how to do it please post.

  4. alexkingorg
    Member
    Posted 7 months ago #

    You need to build the integration with the url shortening service you wish to use. Using the filter Twitter Tools provides.

  5. dnorth
    Member
    Posted 7 months ago #

    I was able to get this to work.

    I add the following to the funciton.php for the template.

    add_filter('tweet_blog_post_url', 'makeShortURL');

    function makeShortURL($URLToConvert) {
    $shortURL= file_get_contents("http://tinyurl.com/api-create.php?url=" . $URLToConvert);
    return $shortURL;
    }

  6. dnorth
    Member
    Posted 7 months ago #

    In the function.php

    1. I added the
    add_filter('tweet_blog_post_url', 'makeShortURL');

    After the frist line <?php

    2. I added the function code before the first function definition in the file.

  7. tonylaw74
    Member
    Posted 7 months ago #

    I tried putting that into my function.php file and it didn't work. Any other ideas? Any other place I can put it?

  8. dnorth
    Member
    Posted 7 months ago #

    I think it will work there (in the function.php for the active theme)

    check out all the formating of the statements, ending ; all that programing stuff has to be correct or it will not work.

    Sorry, I don't have any other ideas.

  9. rmckillen
    Member
    Posted 7 months ago #

    This code will do the trick for bit.ly short URLs:

    function bitly($longUrl) {
      $bitly = json_decode(file_get_contents('http://api.bit.ly/shorten?version=2.0.1&amp;login=YOUR_LOGIN&amp;apiKey=YOUR_API_KEY&amp;longUrl=' . $longUrl), true);
      return $bitly['results'][$longUrl]['shortUrl'];
    }
    add_filter('tweet_blog_post_url', 'bitly');

    Like the others guys have said, find the functions.php for your Wordpress theme (i.e. wp-content/themes/default/functions.php) and place it there.

    Note that you'll need to sign up for a bit.ly account if you don't already have one, and replace YOUR_LOGIN and YOUR_API_KEY with your own.

    If this doesn't work, chances are your PHP installation doesn't allow file_get_contents() to access URLs.

  10. mranderson
    Member
    Posted 6 months ago #

    No need to modify function.php... Just edit the plugin and replace this line

    $url = apply_filters('tweet_blog_post_url', get_permalink($post_id));

    with this

    $url = apply_filters('tweet_blog_post_url', file_get_contents("http://tinyurl.com/api-create.php?url=" . get_permalink($post_id)));

    It should be modified on the next version of Twitter Tools... By the way, it's an awesome plugin, I love it ;)

  11. jamiedavies
    Member
    Posted 6 months ago #

    In response to rmckillen's post re: bit.ly and servers not allowing file_get_contents() I have spent the last few hours coming up with this to get around that.

    Replace
    $url = apply_filters('tweet_blog_post_url', get_permalink($post_id));

    with

    $ch = curl_init("http://api.bit.ly/shorten?format=xml;version=2.0.1&amp;login=USERNAME&amp;apiKey=APIKEY&amp;longUrl=".get_permalink($post_id));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    $xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
    $bitly = $xml->results->nodeKeyVal->shortUrl;
    $url = apply_filters('tweet_blog_post_url', $bitly);

    Hope that helps anyone that needs it.

Reply

You must log in to post.

About this Topic