Facebook _php tutorial for getting Started with PHP development

Source: Internet
Author: User
Tags getting started with php
Objective

The United States has been leading the technology trend, take the open this matter, also from Google Play to Facebook to Twitter, three companies to play the open API. If not, it is unlikely that Facebook and Twitter will emerge in such a short time, giving Google and Microsoft no counter-attack.

If you look at the general Programmer's point of view, the Facebook core table is only 45, but the seemingly simple does not affect the strength of others, such as WordPress table is very few. This period of time in the development of Facebook app, the domestic data is very few, mainly because the country can not access to Facebook, so there are few people to do Facebook development, the data is less natural.

Knowledge Preparation

If you want to do Facebook app development, the first thing to prepare is to flip the wall, because Facebook is outside the wall, don't ask me why, you know. Then you need some basic English level, although Facebook has a simple Chinese, but for the development of all, a lot of things are English, but it doesn't matter, actually very simple, in my so retarded English can be done.

In fact, Facebook supports a variety of development languages, including C #, Python, Javascript, Java, Javascript/php/python and the official SDK for Android and iphone. So, you have one of the above several languages development experience, you can do app development, in fact, I personally think, the most important is the creative +html/css/javascript. Development based on third-party platforms is generally not a very powerful application, but after all, 200 million of the users are not covered, casually pick up a fraction of the users to scare you.

OK, in conclusion, you need one of the c#/java/python/javascript development experience, the official recommendation is PHP5, in fact, not too difficult. The most important is the basic web language, although simple, but very practical. In addition, you may need some simple SQL statements that are not too difficult.

Application

To apply for a Facebook account, if you already have an account, you can ignore this step.

Apply to open Developer permissions, the actual developer function is also as a special app on Facebook, you can click here, it seems I did not find the entrance, click Agree.

Click on the Set up New application button, and Facebook will ask you to verify with your credit card or mobile phone, but just verify your identity, and don't worry.

  

Fill in the basic information of the program, this is the name of your app, you can fill in. Then follow the prompts to step-by-step down, where I am no longer tired of the statement. Tip: The program name can be the same as others, but the canvas page does not conflict, in fact, the Facebook program is http://apps.facebook.com/CanvasPage/this way to access, so ask Canvas Page is globally unique, basically you can think of a good name has been applied, make the whole one bar. The Canvas URL is the address placed on your server because Facebook is integrated in a way that can support IFRAME.

Here you can get a application Key/app id/application secret, where app Key and app ID are often needed for validation in development. More complex settings Let's just ignore it for a while, there is a sandbox mode in advanced that you can choose to enable, because you can put the program into the sandbox during the development process, and you don't need to be seen by others.

Demo

The API provided by Facebook can be said to be very, very powerful, and I have not yet used Renren and the 51 API to know what their API is. Facebook's API can write SQL statements directly, and of course this SQL statement is safely audited. Before I write the demo, I briefly introduce the composition of FACEBOOKAPI.

The Facebook API is mainly composed of fql/fbml/graph api/social plugins, where social plugins mainly provides tools for third-party websites such as OpenID login and like buttons. And FBML is a variant of XHTML, if you use the IFRAME way, you can ignore their markup language, directly write their own OK. So I'm not going to talk about these two kinds of APIs, mainly to talk about FQL and fbml.

FQL is actually the SQL statement provided by Facebook, which can query Facebook's 45 tables by FQL, which is basically no different from the usual SQL statements, but does not support the join query, and can support in queries, as my test probably is.

It is important to note that the content you are looking for must be in the authorization, not that you can simply give an SQL statement to find all the user's data. FQL do not allow * to query all fields, be sure to write directly to the name of the field. For reference on FQL, please visit here.

Speaking of authorization, I have also found a lot of information for this matter, in the case of default authorization, a lot of information such as the user's e-mail is null. Later found to need to be authorized to apply, the official provided a lot of authorization instructions, interested friends can visit here. In JavaScript authorization is the Fb.login need to add authorization parameters, other development languages are similar.

And for the graph API, we can understand as fql of refined version, because many times we may only need simple application, do not need to go directly to the SQL statement, for example, to obtain the user's friend, directly with the my/friends is OK, get the user's activity, direct use me/ Events on the go. We can understand graph Api,facebook so that all content has a unique encoding, whether it's an activity or a picture, an application, a user profile, and so on, and the graph API can access that data through this unique encoding. For resources on the Graph API, please visit here.

Finally, a big meal, the demo code to the whole, I use JavaScript to do this demo, you can choose your own familiar development language. Here is a small trick, if you choose the IFRAME mode instead of FBML, you can deploy the program to your native, and then by modifying the Hosts file, the DNS of your program to point to the local is OK, the advantage is not each time the modification is uploaded to the server.

   <HTML>
<Head>
<Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">
<title>Hello World title >
Head >
< Body >
<scriptsrc= "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/ Jquery.min.js ">

Script>
<DivID= "Fb-root"> Div>
<Scriptsrc= "Http://connect.facebook.net/en_US/all.js"> Script>
<Script>
//initialize the class library with the API you applied to
Fb.init ({appId: ' Application ID ' you have applied for);

//Get Login Status
Fb.getloginstatus (Handlesessionresponse);
functionhandlesessionresponse (respo

< span id= "url" itemprop= "url" >http://www.bkjia.com/phpjc/486114.html www.bkjia.com true http://www.bkjia.com/phpjc/486114.html techarticle Foreword Lao Mei has been leading the trend of technology, take open this matter, From Google to Facebook to Twitter, three companies are playing the open API. If not open ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.