TinyURL, Bit.ly API's

Discussion in 'PHP' started by cyclotron, Sep 2, 2010.

  1. #1
    Hey guys,

    I have to run on-site URL's through the API for some link shortener. Now, sometimes, the API's fail, or you get RATE_LIMIT_EXCEEDED etc. Now there are many link shortener's out there, all with API's so I should be able to create a pretty fail safe way to creating a short URL link.

    Using the API functions, I have this:

    $url = 'http://www.website.com/'.$fetch[id];
    $tiny = get_bitly_short_url(''.$url.'','USER_NAME','API KEY');
    
    
    if ($tiny == "" || $tiny == "RATE_LIMIT_EXCEEDED") {
    
    $tiny = TinyURL($url);
    
    			if ($tiny == "" || $tiny == "RATE_LIMIT_EXCEEDED") {
    				
    				$tiny = $url;
    			}
    
    }
    
    PHP:
    But it seems if the bit.ly API fails, and doesn't work its not passing it through the IF statement. They use cURL so is there a delay or something, or any reason why this wouldn't work?

    Thanks
     
    cyclotron, Sep 2, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    What response are you expecting from the get_bitly_short_url function? If its not processing the proceeding if statement then its not matching either condition. I.E is it returning false on errors, perhaps?
     
    lukeg32, Sep 3, 2010 IP
  3. cyclotron

    cyclotron Active Member

    Messages:
    213
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    73
    #3
    It either returns a string like this:

    bit.ly/12431203 or nothing....

    It's getting entered in the database as either the bit.ly URL it created or nothing...

    But I'm passing an if statement to say if it is "" (blank) make a tinyURL instead.

    But its not jumping to that tinyURL
     
    cyclotron, Sep 3, 2010 IP