21 Incredibly Useful Things You Can Do With cURL and PHP
Like me, if you’ve ever wanted to use a Web Service from a site that doesn’t have that many code examples or a solid API, chances are you may have considered using cURL – a great extension to PHP that allows you to authenticate with websites just like a normal user would. The benefits of doing this are that you’re able to gain access to rich data sources like contact lists, email, statuses and a whole lot more. In this post I’m going to provide you with 20 code examples that’ll help you do some pretty cool things using everything from Bit.ly to Las.fm. Sites covered are Yahoo.com, Last.fm, Amazon, WordPress, Facebook, TwitPic, PayPal, Bit.ly, Twitter, GMail, MySpace, is.gd and IMDB.
- How to shorten a URL through bit.ly
- Get the trending topics on Twitter
- How to get the album covers of your most recent tracks on Last.fm
- Get the list of your Yahoo Contacts via cURL
- How to get your very latest tweets
- How to update your Twitter Status
- How to upload files to Facebook
- How to import your GMail Contacts
- Upload files using Amazon S3 and PHP
- How to login to mySpace through cURL
- How to upload videos to YouTube (API reference)
- How to make a post to WordPress
- How to parse out a movie’s details using IMDB
- How to Scape Bing.com for Search Results
- How to update your Facebook status
- How to upload a picture to TwitPic through cURL
- How to process Payments using PayPal, cURL and CakePHP
- Scrobble tracks to your Last.fm account using cURL
- How to download videos in any format from YouTube
- How to shorten a URL using the is.gd Shortening service
- How to grab the number of subscribers from your Google Reader Account




11 Comments
Really nice!
Really nice!
I believe the facebook update one is the really old version which doesn't work anymore
How to fetch friend image after logging in facebook or myspace or orkut using curl?
I've been personally using the Official API for all Facebook related things for a while now, but if you're interested in some alternative code for achieving this via CURL, here's a nice little snippet from Snipplr http://snipplr.com/view/29070/how-to-change-faceb...
I've been personally using the Official API for all Facebook related things for a while now, but if you're interested in some alternative code for achieving this via CURL, here's a nice little snippet from Snipplr http://snipplr.com/view/29070/how-to-change-faceb...
I've been personally using the Official API for all Facebook related things for a while now, but if you're interested in some alternative code for achieving this via CURL, here's a nice little snippet from Snipplr http://snipplr.com/view/29070/how-to-change-faceb...
It depends on what you're trying to do. If you're only interested in the thumbnail (and not a higher res version) you should just be able to load in the URL to their friend profile directly and use regular expressions to extract the URL to their friend image. That said, it might just be easier for you to try doing this via the Facebook API as they have methods for grabbing friend images fairly painlessly.
Thank you!
I have done this:
$login_email = XXXXXXXXX;
$login_pass = 'XXXXXXXXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/profile.php?id='.$id);
$page = curl_exec($ch);
$profile_pic=substr($page,strpos($page,'http://profile.'),(strpos($page,'class="p"')-strpos($page,'http://profile.'))-2);
echo '<img src="'.$profile_pic.'" width="50">';
Thanx for your code. Please let me know if there is a better solution