Join Joseph Lowery for an in-depth discussion in this video Interfacing with Facebook, part of Up and Running with Cloud Service APIs.
It's only fitting that Facebook have one of, if not the most robust service APIs available, of all the social media platforms. As the grand daddy of them all, its very existence depends on connections and extending their network. In this lesson, I'll show you how to get set up as a Facebook developer and start exploring all the many options they make available. Let's begin with registration. The Facebook developer registration, a necessary step to make full use of the range of their API services, is basically an extension of the Facebook membership.
So, you have to have a Facebook account and be logged in before you can take the next step. I'm here on the Facebook Developers page, and I've already logged in to Facebook. Now, there used to be a big Register Now button, but it's not so obvious right now as to what to do. So, if you go up to Apps and choose that option, you'll get a sub-menu, Register as a Developer. Let's choose that. Now, I'm asked if I want to accept the Facebook policies, and I say yes, and then click Next.
And, they'll need my phone number because they're going to send a code, so I'll go ahead and enter that. So I'll press Tab, and now I have actually two options. I can either get it as text, which I have a mobile phone, so I'll use that. Or it can send it via phone call if I was not able to accept a text. And pretty quickly, I get a text message on my cell phone, complete with a confirmation code, which I'll enter into the Confirmation Code field. And then click Register. And now I have successfully registered as a Facebook developer.
So let's click Done, and I am taken to the Docs page. And now if you go up and check Apps, instead of Register as a Developer, it says Create a New App. Now to get a better grasp of all that Facebook connected apps are capable of, let's click Products. The first option that we see on navigation over on the left is one of Facebook's most commonly implemented APIs, Login. With the Login with Facebook API integration, you not only get a quick trusted way for your users to sign in to your app, you also get access to their public profile and friends list.
Sharing is Facebook's next overall API category. Within it, there are three subsections. Mobile Share Dialogs, the first one, will allow your users to share their in-app experiences with their Facebook social network. Next, Social Plugins. These are the ubiquitous like and share buttons. We've all seen these on a myriad of webpages and through the Facebook API, you can also include them in your app as well. Finally, there's Custom Stories. This is Facebook's most advanced sharing implementation.
A custom story takes sharing to the next level and allows a deeper integration with app related events. Whether it's finishing a book on Goodreads or tracking a marathon runner on Race-Keeper. Facebook also has an API dedicated to gaming. Games are a huge aspect of Facebook with over 250 million players per month. The iOS and Android platforms are fully supported, each with their own developer center and SDK. You can charge for your Facebook games and even run ads within them, and of course, the social aspect of Facebook can be fully integrated into your game, if desired.
Now to handle all this traffic and to encourage more, Facebook now offers its own infrastructure for mobile apps with Parse. Parse handles data storage, scalable server maintenance, cron jobs, analytics, and much more. So as you can see, Facebook has a lot to offer mobile app developers. Now, let's just take a look at how the API is structured to see how you can get and post content. So from the main navigation, click Docs.
Now from here, you'll get a dedicated SDKs and details for iOS, Android, the web, and online gaming. Now let's scroll down a bit till over on the left hand side, you see the APIs section. Let's click the first one listed, Graph API. The Graph API is Facebook's main gateway whether you're retrieving data or posting content. Because it's so central, Facebook includes a tool called the Graph Explorer that allows you to try out different scenarios before you commit to code. So, let's give it a whirl.
From the main navigation, I'm going to go up and choose Tools, and then Graph Explorer. The first step in any communication with a Facebook API is to gain access. And for that, you'll need an access token. Access tokens allow data to be exchanged securely and are typically generated when the Facebook login procedure is used. Now we can simulate that action with a Graph Explorer by just clicking the Get Access token button you see here. When you do, you'll see a dialog appears that offers more specific options for information protected by user data permissions, friends' data permissions, and also extended permissions.
We're going to start by just going with the default and not pre-selecting anything. So I'll click Get Access Token in the dialog, and Facebook responds by telling you that it will get my profile since I'm already logged in, and my friend list, let's click Okay. You can now see a very long hash string that's been generated and set up as the access token. And in the HTTP field, right next to the Get button, we can see what's being passed in, which consists of a node ID and two fields, the ID and name.
Below on the right, you can see the adjacent equivalent, that's who made the access token request, me. Now, let's see what info I can get about myself. So, I'm going to delete the the argument in the HTTP field and just enter the keyword, me. Now, I'll click Submit to process the request. As you can see, we get a fair amount of results back over on the right here. There's my name, my city, a quote, the school I went to, college I went to, and so on. Now you can hone in on that information by changing the fields that are passed in.
Now we could go ahead and generate the access token again, and then bring up that whole dialog box, or I could just click on the plus arrow right under the Node section that you see here. And let's just hone in on the quotes. I'm going to scroll down a bit. And there are quotes, so I'll choose that. And you can see a little reminder here that says, click Submit to Refresh, so I'll go ahead and click Submit. And now we're restricted to just the quote. However you handle submitting the HTTP request to Facebook, you can use the Graph Explorer to retrieve example values that you can then interact with through your app.
It's just the start of what's possible with the Facebook APIs.
First, there are the popular Google cloud services and device-specific APIs for iOS, Android, and Windows Phone. Then there are APIs to connect to followers on platforms like Facebook and Twitter and even pull images from Flickr. For some really interesting data, Joe shows how to access corporate APIs from companies like Citrix and General Motors. (Imagine getting vehicle data straight from GM.) Last, he shows how to leverage public sector APIs and mine data from the national census, weather bureaus, and even federal job boards. Learn how to make your web projects stand out with cloud services.
- Working with Google Cloud APIs
- Connecting to mobile devices via APIs
- Interfacing with Facebook and managing a Twitter feed
- Utilizing the Google infrastructure in your own apps
- Working with the General Motors API
- Understanding public sector APIs