permalink

11

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.

 

  1. How to shorten a URL through bit.ly
  2. Get the trending topics on Twitter
  3. How to get the album covers of your most recent tracks on Last.fm
  4. Get the list of your Yahoo Contacts via cURL
  5. How to get your very latest tweets
  6. How to update your Twitter Status
  7. How to upload files to Facebook
  8. How to import your GMail Contacts
  9. Upload files using Amazon S3 and PHP
  10. How to login to mySpace through cURL
  11. How to upload videos to YouTube (API reference)
  12. How to make a post to WordPress
  13. How to parse out a movie’s details using IMDB
  14. How to Scape Bing.com for Search Results
  15. How to update your Facebook status
  16. How to upload a picture to TwitPic through cURL
  17. How to process Payments using PayPal, cURL and CakePHP
  18. Scrobble tracks to your Last.fm account using cURL
  19. How to download videos in any format from YouTube
  20. How to shorten a URL using the is.gd Shortening service
  21. How to grab the number of subscribers from your Google Reader Account

11 Comments

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

      • 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&#039 ;) ;
        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");

Leave a Reply

Required fields are marked *.

*