Bitly class

bit.ly allows users to shorten, share, and track links (URLs). Reducing the URL length makes sharing easier.

Grab your copy

Download Bitly (2.0.2)

Follow development on GitHub

Follow Bitly

About

PHP Bitly is a (wrapper)class to communicate with bit.ly.

License

Bitly is BSD licensed.

Documentation

The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc.

More documentation

Sites that use this class

Do you know a site that uses this class? Use the form below.

Comments

Tijs Verkoyen

Tijs Verkoyen wrote:
01/08/2009

Changelog since 1.0.0:
- corrected some documentation
- wrote some explanation for the method-parameters

waldo malqui silva

waldo malqui silva wrote:
22/09/2009

ERROR : CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

Solution:

if ( ini_get('open_basedir') == '' ) {
$options[CURLOPT_FOLLOWLOCATION] = true;
}

Steve

Steve wrote:
24/09/2009

Hi

Great class, one question though. Should we be encoding URL's before passing into your shorten method as the bit.ly api requires encoded URL's?

If so it would be cleaner to do the encode within the method.

Steve

Steve wrote:
24/09/2009

Just looked at the code more closely and I see you do encode! My bad :)

gentax

gentax wrote:
30/09/2009

thanks guy!
that's a wonderful help!
great class

Bruce

Bruce wrote:
18/10/2009

Great class. Just what I was looking for.
Thank you! :)

OrT

OrT wrote:
13/11/2009

Excellent work, and big thanks for the support

Tijs

Tijs wrote:
02/12/2009

@Mike: just ran all my tests again and no errors.

Martin

Martin wrote:
13/02/2010

I wan´t to set the publishToHistory to false.. But it won´t work. Could you please tell me, how I can stop it?

Tijs Verkoyen

Tijs Verkoyen wrote:
16/02/2010

Changelog since 1.0.1
- each URL will be added into your history, removed the history parameter

gombile

gombile wrote:
27/02/2010

Thanks for your bitly api PHP class

Tom

Tom wrote:
27/03/2010

Hi,

Thanks for the class (although I can't use it yet)
Here's what I'm getting already with only the require_once line:
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in bitly.php on line 37

Any ideas?

Thanks,

Tom

Tom

Tom wrote:
27/03/2010

Ok switched to php5, sorry about that :)

I still get these 2 errors though :

Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /include/bitly.php5 on line 144

Fatal error: Uncaught exception 'BitlyException' with message 'Invalid JSON-response' in /include/bitly.php5:204 Stack trace: #0 /include/bitly.php5(316): Bitly->doCall('errors', NULL) #1 /test.php5(11): Bitly->errors() #2 {main} thrown in /include/bitly.php5 on line 204

Thanks

Resideo.com

Resideo.com wrote:
21/06/2010

Thanks a bunch! Your class was extremely easy to implement

Tijs

Tijs wrote:
15/09/2010

Changelog since 2.0.1
- added some new method to reflect the latest version of the API, new methods are: clicksByMinute, countries, info, lookup, referrers

Peter F. Aquart

Peter F. Aquart wrote:
20/09/2010

I'm getting similar issues to those above referring to the invalid json response. The curl call spits out a valid success response, and the long links are being added to my bit.ly account, but the data is not being passed out of doCall. Any thoughts?

Tijs Verkoyen

Tijs Verkoyen wrote:
13/10/2010

@Peter F. Aquart: Just ran my tests again and can't find any errors. Which version of the class are you using?

Masterphreak

Masterphreak wrote:
28/10/2010

I'm having the same problem as @Peter F Aquart. I'm using the latest version of the class, 2.0.1

When I run the script in my browser it just dumps the json response to the browser and quits.

Tijs Verkoyen

Tijs Verkoyen wrote:
28/10/2010

@Masterphreak: can you email your code (emailaddress in the class)

Will Mason

Will Mason wrote:
04/12/2010

@Tijs: in your code you mention that only bit.ly and j.mp domains are allowed, custom domains will be handled by using the correct login. I don't understand this... I would like to use a custom domain I have with bit.ly. Thanks!

Will Mason

Will Mason wrote:
11/01/2011

Ok, now I get it. My account automatically gives me my pro domain.

Thanks for the class. Major time saver.

Viagra

Viagra wrote:
03/02/2012

, http://www.viagraonlinewwv.com/ Viagra for sale, qauh, http://www.genericviagrawww.com/ Viagra generic, 804733, http://www.medsonlineww.com/ Viagra dosage, wxmxtg,

Viagra levitra compared

Viagra levitra compared wrote:
03/02/2012

, http://www.viagraonlinewwv.com/ Viagra price, mwg, http://www.genericviagrawww.com/ Generic viagra, twswr, http://www.medsonlineww.com/ Buying viagra online, 8475,

Viagra

Viagra wrote:
03/02/2012

, http://www.viagraonlinewwv.com/ Viagra, 6504, http://www.genericviagrawww.com/ Generic viagra, mwrd, http://www.medsonlineww.com/ Buy viagra on the internet, 432,

Viagra

Viagra wrote:
03/02/2012

, http://www.viagraonlinewwv.com/ Viagra online without prescription, %]], http://www.genericviagrawww.com/ Generic viagra, %-PPP, http://www.medsonlineww.com/ Buy generic viagra, :[[[,

Generic viagra prices

Generic viagra prices wrote:
04/02/2012

, http://www.viagraonlinewwv.com/ Viagra online without prescription, 072173, http://www.genericviagrawww.com/ Discount viagra, :-((, http://www.medsonlineww.com/ Viagra online, 236453,

, http://www.viagraonlinewwv.com/ Viagra online, :-(, http://www.genericviagrawww.com/ Cheap viagra, czpvb, http://www.medsonlineww.com/ Buy generic viagra on line, 0485,

Viagra

Viagra wrote:
04/02/2012

, http://www.viagraonlinewwv.com/ Viagra price, 8-PP, http://www.genericviagrawww.com/ Generic viagra, :OO, http://www.medsonlineww.com/ Buy viagra online inurl, :),

Generic viagra prices

Generic viagra prices wrote:
04/02/2012

, http://www.viagraonlinewwv.com/ Buy viagra online, =-), http://www.genericviagrawww.com/ Viagra generic, 726, http://www.medsonlineww.com/ Viagra levitra compared, lylk,

Generic viagra prices

Generic viagra prices wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Viagra for sale, 642, http://www.genericviagrawww.com/ Generic viagra, >:(, http://www.medsonlineww.com/ Generic viagra prices, 49517,

Viagra

Viagra wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Buy viagra online, >:-[, http://www.genericviagrawww.com/ Generic viagra, 181368, http://www.medsonlineww.com/ Cheap viagra, hyeuq,

Generic viagra prices

Generic viagra prices wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Viagra online, cyqx, http://www.genericviagrawww.com/ Viagra, fkkqy, http://www.medsonlineww.com/ Order viagra online cheap prices, 8[[[,

Generic viagra prices

Generic viagra prices wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Viagra, 520, http://www.genericviagrawww.com/ Cheap viagra, tkknnh, http://www.medsonlineww.com/ Buy viagra online, aosv,

Viagra levitra compared

Viagra levitra compared wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Viagra price, :]], http://www.genericviagrawww.com/ Generic viagra online, 87050, http://www.medsonlineww.com/ Cheap viagra online, 8-D,

Does generic viagra work

Does generic viagra work wrote:
05/02/2012

, http://www.viagraonlinewwv.com/ Viagra, crqc, http://www.genericviagrawww.com/ Cheap viagra, diwbbf, http://www.medsonlineww.com/ Cialis comparison viagra, fxzft,

, http://www.viagraonlinewwv.com/ Buy viagra online, =-]]], http://www.genericviagrawww.com/ Generic viagra, mnfjs, http://www.medsonlineww.com/ Viagra stories, 583423,

Add your comment

If you have some feedback, a remark or you just want to say something. Go ahead, use the form below.

 

:

:

:

About me?

Well, I'm Tijs Verkoyen, a self employed Belgian PHP-developer at Sumo Coders.

If you want to know more about me, check my blog (Dutch).

If you really like my work and want to support me, feel free to use the donate-button below.

Spoon

At both companies, we use Spoon. Spoon is a PHP5 Library that we use for building all our Web 2.0 applications.

The classes that you can download from this website are standalone, so each developer is free to use a library/framework/… he likes best.