Wednesday, February 16, 2011

Simple PHP oAuth example for Facebook Graph API

I needed to implement oAuth for the the Facebook graph API today and couldn't find any straight forward php examples so I thought I would post this in case any else is in a similar situation.

The basic process for the authentication is outlined here so I won't go into the details of it.  In the example below the bit you'll need to take note of is the "scope" parameter in the link, this defines the permissions you are requesting.  To see a full list of available permissions click here.

You'll also need to sign up for an API key first and register your application with Facebook, you can sign up here.

Step 1:
In your page make a link like this:

<a href="<?=FACEBOOK_APP_ID?>&redirect_uri=
&scope=offline_access,user_checkins,friends_checkins">Connect with Facebook</a>

Step 2:
Create a page called fb_oauth_return.php which contains the following code


  $code = $_GET["code"];    
  $url = ''.FACEBOOK_APP_ID.'&redirect_uri='.urlencode('').'&client_secret='.FACEBOOK_SECRET.'&code='.$code;
  $buffer = curl_exec($curl_handle);
  if(strpos($buffer, 'access_token=') === 0)
   //if you requested offline acces save this token to db 
   //for use later   
   $token = str_replace('access_token=', '', $buffer);
   //this is just to demo how to use the token and 
   //retrieves the users facebook_id
   $url = ''.$token;
   $buffer = curl_exec($curl_handle);
   $jobj = json_decode($buffer);
   $facebook_id = $jobj->id;
   //do error stuff
 //do error stuff

And that's it.  If you requested offline access you'll need to save the token to your database so that you can use it to make requests on the user's behalf later.

Friday, February 11, 2011

Nokia + WP7 and the fate of Meego

Big news for Nokia and WP7 fans today with the announcement of a partnership between Nokia and Micosoft to release a range of WP7 based Nokia handsets.  Hopefully for Nokia this can help increase their flagging smartphone market share.  However for me this raises some importatnt questions about the fate of Meego which I was really looking forward to seeing hit the handset market this year.  Sadly it looks like there will not be the proliferation of Meego devices I was hoping to see.  Nokia released a rather cryptic statement about future Meego development:

"MeeGo will place increased emphasis on longer-term market exploration of next-generation devices."

What this actually means remains to be seen but they have confirmed they will release one Meego handset this year.  Given that the scope of Meego is quite broad, aimed at everything from in vehicle systems to netbooks we may see it popping up on other devices soon it's clear that it will not be Nokia's focus for it's return to the smartphone market in the short term.

I hope there is still a future for Meego on handsets especially with the announcement of the Dalvik Alien VM for running Android apps on non Android devices which would combine the existing Android development ecosystem with Nokia's handsets.  Given that Meego is a partnership between Intel and Nokia I would be interested to hear Intel's thoughts on this new deal.

This is certainly sad news for fans of Maemo 5, Meego and open source operating systems generally but WP7 is a solid mobile OS and Nokia definitely need to move away from Symbian if they want to be taken seriously in the high end smartphone market.  This new gambit with WP7's success will be highly dependent on how much traction WP7 can achieve with consumers over the next year or so.  I'm also guessing that Microsoft is hoping to piggy back on Nokia's brand reputation and following in order to get the general public interested in WP7 which, while still in it's early stages, has yet to gain much of a following amongst consumers.

While Maemo 5 is a truly excellent mobile OS and Meego has tons of potential I fear that this may be the end of Meego handsets as a serious competitor to Android and iOS, at least in 2011.


Wednesday, February 9, 2011

Backpacking Essentials for the Geek - what to take with you

I usually write about tech but this week I thought I would try something a little different and talk about setting up the perfect backpack for the travelling geek.  If you're planning a long backpacking trip there are a few items I find make life on the road a bit more comfortable.

The essentials:

1. A Netbook
Netbooks are a blessing for the modern backpacker and provide several advantages over lugging around a laptop.  Most 9-inch netbooks weigh less than a kilogram but provide you with a fully functional computer that you can take anywhere.  They are also crazy cheap($300 - $400) so losing/getting wet/stolen is not the huge financial blow it would be with an expensive laptop.  Your netbook will let you do all your skype calling, emailing, photo uploading as well as watching episodes and movies in bed on your downtime nights.  Also given that most hotels and hostels have wifi you can get internet access pretty much anywhere and you can now avoid using the painfully slow, virus laden public access computers in your hostel.  Personally I use an Asus T91 running Ubuntu, it's only 9" and weighs around 900 grams so you barely notice you are carrying it.

Asus Eee PC T91SA-VU1X-BK 8.9-Inch Intel Atom Netbook Computer (Black)
Asus eee Netbook, 9" and 900 grams awesome for your backpack

2. A carrier unlocked Smartphone
In most countries getting a pre-paid SIM card takes about ten minutes and is super cheap so having an unlocked phone will end up saving you a ton of money and hassle in the long run.  If you're like me and you're not willing to take an awesome expensive camera around with you I find my HTC Hero and HTC Desire have great cameras and replace the need to take a point and click with me.  It's also an Mp3 player and GPS so that's two less things to carry.

3.  Spare Rechargeable Batteries
I always carry rechargeable batteries with generic plugs for recharging my phone, Nintendo DS and kindle when I don't have access to mains power as well as a spare phone battery.  Having your mp3 player running out of power 5 hours into a 30 hour train ride is no fun so make sure you always have backup power.

New Trent Dual-port Pack IMP50D 5000mAh External Battery pack for Apple iPad, iPhone 4G 4, iPhone 3G 3GS, iPod Touch (1G 2G 3G), Motorola Droid phones, HTC Android Phones , Blackberry (curve, tour, bold, storm) Black
Something like this portable battery pack

4. Headphones and Adapters
A good pair of bud earphones is essential, you can take over the ear style ones but you always need to be precious with them so they don't get crushed and ultimately I don't think the added sound quality is worth the effort.  The ear plug style buds are best for this as they blog out more external sound which you will really appreciate when you are on a bus with blaring Hindi pop music.  Also take a headphone splitter so that you can share what you are watching/listening to with the person next to you.  I also recommend picking up an adapter for the headphone jacks they use on airplanes so you can use your own headphones with the in flight entertainment.

Sennheiser CX300-B In-Ear Stereo Headphone
These do a great job of blocking out external sound

5. Cables, Adapters and Chargers
The possibilities here are endless but these are what I always take:
- A short length of cat 5
- Mini USB to USB
- Micro USB to USB
- 3.5mm jack to stereo RCA
- 3.5mm to 3.5mm stereo cord
- VGA Cable
- DVI to VGA Adapter
- Headphone Splitter
- AC Power adapters for various countries
- AC power to USB
- A multi-card reader

6. Data Storage (The Cloud is your friend)
You'll want somewhere to store your data while you are on the road and if you want to bring episodes and movies with you then you'll need some storage.  There are a few options here either and external drive, usb sticks and memory cards.  The external drive will give you the most bang for your buck but after having two of them die on me while travelling I decided to buy a bunch of large memory sticks and memory cards instead, a little pricier but worth it.  Make sure you back up your photos to the cloud using something like DropBox or Ubuntu One as often as possible, backing up photos to your memory stick won't do you any good if you lose your backpack.

7. A torch + spare batteries
This one is a no brainer and you'll be surprised how often you use it.  I use a mini maglite which does a great job.

MAGLITE M2A016 AA Mini Flashlight, Black
Definitely worth the space in your pack
8. Passport Photos and a Pen
Most countries still require filling out visa applications and entry cards so having a pen means you can fill everything out and get through customs as fast as possible.  Also most countries will require a passport photo attached to the visa application and not needing to get photos at the only photo booth in the airport will save some serious hassle and cash.  Just remember not to put the photos in with your check-in luggage!

Nice to have:
1. A Nintendo DS
Amazing battery life, tons of games and r4 cards plus wifi multiplayer, why wouldn't you want to.

2. A Kindle
Awesome for reading on the go.  Great battery life, small and light plus the global 3g coverage if you go for the more expensive model means you can shop for books online almost anywhere.

3. A hip flask
Really great to have on a long train trip or a long day of hiking or trekking where space and weight are at a premium.

4. Travel speakers
If you can get some good travel speakers they really come in handy.