Home Backend Development PHP Tutorial Introduction to PHP development for Facebook applications_PHP tutorial

Introduction to PHP development for Facebook applications_PHP tutorial

Jul 13, 2016 pm 05:41 PM
facebook php Preface exist application develop open technology Beginner's guide trend of

Foreword

The United States has always been leading the trend of technology. Take the issue of openness as an example. From Google Play to Facebook to Twitter, the three companies are having fun with open APIs. If it were not for openness, it is estimated that Facebook and Twitter would not have emerged as such in such a short period of time, leaving Google and Microsoft without the ability to fight back.

If you look at it from the perspective of an average programmer, Facebook only has 45 core tables, but its seeming simplicity does not affect its power. For example, WordPress has very few tables. During this period of time, I was working on Facebook App development, and there was very little domestic information. Mainly because Facebook was not accessible in China, so there were very few people doing Facebook development, and there was naturally less information.

Knowledge preparation

If you want to develop a Facebook App, the first knowledge preparation is to circumvent the wall, because Facebook is outside the wall. Don’t ask me why, you know. Then you also need some basic English proficiency. Although Facebook has simple Chinese, for developers, many things are still in English, but it doesn’t matter, it is actually very simple, and I can handle it with a weak English like me.

In fact, Facebook supports multiple development languages, including C#, Python, Javascript, Java, etc. There are official SDKs for Javascript/PHP/Python, Android and iPhone. So, if you have development experience in one of the above languages, you can do App development. In fact, I personally think that the most important thing is creativity + Html/CSS/Javascript. Developments based on third-party platforms are generally not very powerful applications, but after all, 200 million users are not guaranteed. Just picking up a small number of users will scare you to death.

OK, to summarize, you need one of the development experience in C#/Java/Python/Javascript. The official recommendation is PHP5, which is actually not too difficult. The most important thing is the basic web language, which is simple but very practical. In addition, you may need some simple Sql statements, which are not too difficult.

Apply

Apply for a Facebook account. If you already have an account, you can ignore this step.

Apply to open Developer permission. The actual Developer function is also placed on Facebook as a special App. You can click here. It seems that I did not find the entrance. Just click Agree.

Click the Set Up New Application button. At this time, Facebook will ask you to verify with your credit card or mobile phone. In fact, it is just to verify your identity, so don’t worry.

 

Fill in the basic information of the program. This is the name of your App. You can fill it in casually. Then just go down step by step according to the prompts, I won’t repeat them here. Tip: The program name can be the same as others, but the Canvas Page cannot conflict. In fact, the program to access Facebook is accessed using http://apps.facebook.com/CanvasPage/, so the Canvas Page is required to be globally unique. Basically, all the good names you can think of have been applied for, so just make one. The Canvas URL is the address placed on your server, because Facebook can support iFrame integration.

At this point you can get an Application Key/App ID/Application Secret. App Key and App ID are often used for verification in development. Let’s ignore the more complicated settings for now. There is just one thing. There is a Sandbox Mode in Advanced that can be selected as Enable, because you can put the program in the sandbox during the development process without others seeing it.

Demo

The API provided by Facebook can be said to be very, very powerful. I have not used the APIs of Renren and 51 yet, and I don’t know what their APIs are like. Facebook's API can directly write Sql statements. Of course, this Sql statement will undergo security review. Before writing the Demo, I will briefly introduce the composition of Facebook API.

Facebook’s API is mainly composed of four parts: FQL/FBML/Graph API/Social plugins. Social plugins mainly provide some tools to third-party websites, such as OpenID login and Like button. FBML is a variant of xHTML. If you use iFrame, you can ignore their markup language and just write it yourself. So I won’t talk about these two APIs for the time being, but mainly talk about FQL and FBML.

FQL is actually the Sql statement provided by Facebook. You can query Facebook's 45 tables through FQL. It is basically no different from ordinary Sql statements, but it does not support join queries. It can support in queries. According to my test That's probably it.

It should be noted that the content you are querying must be authorized. It does not mean that you can find all user information by just giving an Sql statement. FQL does not allow the use of * to query all fields. The name of the field must be written directly. For reference materials on FQL, please visit here.

Speaking of authorization, I have found a lot of information on this matter before. In the case of default authorization, many information such as the user's email are null. Later I found out that I need to apply for authorization. The official provides a lot of authorization instructions. Interested friends can visit here. Authorization in Javascript means adding authorization parameters to FB.login. Other development languages ​​are similar.

As for Graph API, we can understand it as a refined version of FQL, because many times we may only need simple applications and do not need to directly check Sql statements. For example, to get the user’s friends, just use my/friends. OK, to get the user's activities, just use me/events directly. We can understand Graph API in this way. Facebook allows all content to have a unique encoding, whether it is activities, pictures, applications, user profiles, etc., and Graph API can access this information through this unique encoding. For reference materials on the Graph API, please visit here.

Finally, let’s finish the demo code. I used Javascript to make this demo. You can choose a development language you are familiar with. Here’s another little tip. If you choose iFrame instead of FBML, you can deploy the program to your local machine, and then point the DNS of your program to the local machine by modifying the Hosts file. The advantage is that you don’t have to do it every time. Modifications are uploaded to the server.

  <html>
<head>
<metahttp-equiv="content-type"content= "text/html; charset=utf-8">
<title>Hello Worldtitle >
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>
//Use the API you applied for to initialize the class library
FB.init({appId: ‘Application ID you applied for’});

//Get login status
FB.getLoginStatus(handleSessionResponse);
functionhandleSessionResponse(respo

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486114.htmlTechArticleForeword The United States has always been leading the trend of technology. Take the matter of openness as an example, it also started from Google Play From Facebook to Twitter, the three companies are having a great time opening APIs. If it is not on...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

A list of historical prices since the birth of Bitcoin BTC historical price trend chart (Latest summary) A list of historical prices since the birth of Bitcoin BTC historical price trend chart (Latest summary) Feb 11, 2025 pm 11:36 PM

Since its creation in 2009, Bitcoin’s price has experienced several major fluctuations, rising to $69,044.77 in November 2021 and falling to $3,191.22 in December 2018. As of December 2024, the latest price has exceeded $100,204.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Bitget Exchange official website login latest entrance Bitget Exchange official website login latest entrance Feb 18, 2025 pm 02:54 PM

The Bitget Exchange offers a variety of login methods, including email, mobile phone number and social media accounts. This article details the latest entrances and steps for each login method, including accessing the official website, selecting the login method, entering the login credentials, and completing the login. Users should pay attention to using the official website when logging in and properly keep the login credentials.

See all articles