funp 開發者俱樂部 十月份聚會

51
funP 開開開開開開 開開開開開 [email protected]

Upload: tutchiio

Post on 17-May-2015

3.883 views

Category:

Technology


2 download

DESCRIPTION

介紹如何開發 facebook application

TRANSCRIPT

Page 1: funP 開發者俱樂部 十月份聚會

funP 開發者俱樂部

十月份聚會[email protected]

Page 2: funP 開發者俱樂部 十月份聚會

> 33,000 apps

Page 3: funP 開發者俱樂部 十月份聚會

< 10 apps

Page 4: funP 開發者俱樂部 十月份聚會

fbOpenhttp://developers.facebook.com/fbopen/

shindighttp://incubator.apache.org/shindig/

Page 5: funP 開發者俱樂部 十月份聚會

Introduction

Page 6: funP 開發者俱樂部 十月份聚會

Canvas

Your application Here

Page 7: funP 開發者俱樂部 十月份聚會

應用程式頁面

Your application Here

Page 8: funP 開發者俱樂部 十月份聚會

Profile box

Wid

e

Narro

w

Page 9: funP 開發者俱樂部 十月份聚會

個人檔案元件

Wid

e

Narro

w

Page 10: funP 開發者俱樂部 十月份聚會

Mini-feed Newsfeed

Page 11: funP 開發者俱樂部 十月份聚會

最新動態 麻吉快報

Page 12: funP 開發者俱樂部 十月份聚會

事件

最新動態Mini-feed

麻吉快報Newsfeed

Page 13: funP 開發者俱樂部 十月份聚會

Request / Notification

Page 14: funP 開發者俱樂部 十月份聚會

請求

Page 15: funP 開發者俱樂部 十月份聚會

Flow

facebookYourApp

Serveruser

request

request

API / FQLcalls

API / FQLresults

response

FBMLFBJS

http://apps.facebook.com/myapp/page.php?q=abc

http://myappserver.com/page.php?q=abc

Users.getInfo()

<xml> … </xml>

<fbml> … </fbml>

<html> … </html>

Client library

Page 16: funP 開發者俱樂部 十月份聚會

facebook

YourApp

Server

Client library

funP麻吉

Modified client library

Page 17: funP 開發者俱樂部 十月份聚會

Development building blocks

API

FBML

FQL

FBJS

Page 18: funP 開發者俱樂部 十月份聚會

Facebook API

Page 19: funP 開發者俱樂部 十月份聚會

API

• Users– getInfo

• Friends– get

• Groups– getMembers

• FQL– query

• Fbml– refreshImgSrc

• Feed– publishUserAction

• Notifications– send

• Profile– setFBML

Page 20: funP 開發者俱樂部 十月份聚會

API Test Consolehttp://developers.facebook.com/tools.php?api

Page 21: funP 開發者俱樂部 十月份聚會

FQL

Facebook Query Language

Page 22: funP 開發者俱樂部 十月份聚會

tables

Frienduid1uid2

Useruidnamepicsex

Groupgidnamepicdesc

Groupmemberuidgidposition

Page 23: funP 開發者俱樂部 十月份聚會

Scenario

• 顯示有使用同一個 application的好友

$ids = friends.getAppUsers();$users = users.getInfo( $ids, array(‘name’, ‘pic’) );

Page 24: funP 開發者俱樂部 十月份聚會

FQL

$query = “

SELECT uid, name, pic FROM user

WHERE uid IN (

SELECT uid2 FROM friend

WHERE uid1 = $user

) AND is_app_user

“;

$users = fql.query($query);

Page 25: funP 開發者俱樂部 十月份聚會

Why FQL?

• reduce the number of requests necessary

• reduces bandwidth and parsing costs

• consistent, unified interface

Page 26: funP 開發者俱樂部 十月份聚會

FBML

Facebook Mark-up Language

Page 27: funP 開發者俱樂部 十月份聚會

顯示複雜的原件<fb:multi-friend-selector/>

Page 28: funP 開發者俱樂部 十月份聚會

一致的外表

<fb:tabs/> <fb:tab-item/>

Page 29: funP 開發者俱樂部 十月份聚會

邏輯判斷• <fb:visible-to-owner/>

• <fb:visible-to-user/>

• <fb:visible-to-friends/>

Page 30: funP 開發者俱樂部 十月份聚會

動作• Visibility

– clicktoshow– clicktohide– clicktotoggle

• Mock AJAX – clickrewriteid– clickrewriteurl– clickrewriteform

Page 31: funP 開發者俱樂部 十月份聚會

FBML Test Consolehttp://developers.facebook.com/tools.php?fbml

FBML

HTML

Preview

Page 32: funP 開發者俱樂部 十月份聚會

FBJS

Facebook Javascript

Page 33: funP 開發者俱樂部 十月份聚會

Security

function foo(bar) {var obj = {prop: bar}; return obj.prop;

}

function a12345_foo(a12345_bar) {

var a12345_obj = {prop: a12345_bar};

return a12345_obj.prop;

}

Page 34: funP 開發者俱樂部 十月份聚會

Security

document.getElementById(‘div’).innerHTML = ‘abc’;

document.getElementById(‘div’).setInnerFBML(‘abc’);

v = document.getElementById(‘input_text’).value;

v = document.getElementById(‘input_text’).getValue();

document.getElementById(‘p').style.display = 'none';

document.getElementById(‘p').setStyle(‘display’,'none‘);

Page 35: funP 開發者俱樂部 十月份聚會

FBJS - libraries

• Ajaxvar ajax = new Ajax();

ajax.ondone = function(data) { …}ajax.post(url);

• Dialogsvar d = new Dialog();

d.showMessage('Dialog', 'Hello World.');

• AnimationAnimation(document.getElementById('container')).

to('height', '0px').to('width', '0px').

to('opacity', 0).blind().hide().go();

Page 36: funP 開發者俱樂部 十月份聚會

Tutorial

Page 37: funP 開發者俱樂部 十月份聚會

Getting started

1. add the “Developer” app

2. create your app

3. download the client lib

4. fill in api key & secret

5. hello facebook

Page 38: funP 開發者俱樂部 十月份聚會

1. add the “Developer” app

• go to http://www.new.facebook.com/developers/

• click “Allow”

Page 39: funP 開發者俱樂部 十月份聚會

2a. create your app

• click “set up new application”

Page 40: funP 開發者俱樂部 十月份聚會

2b. edit app settings

1. fill in application name

2. check to agree terms

3. show optional fields

4. fill in callback url ( real url of your app on your server)

5. fill in canvas page url ( virtual url of your app on facebook ) and make sure it is Available

Page 41: funP 開發者俱樂部 十月份聚會

facebookYourApp

Server

request

Canvas Page URLhttp://funp.com/apps/funpresent/

request

Callback URLhttp://example.com/funpresent/

Page 42: funP 開發者俱樂部 十月份聚會

2c. edit app settings

6. select “yes” for Can your application be added on Facebook?

7. check “users” for Who can add your application to their Facebook account?

8. check Developer Mode

9. submit

Page 43: funP 開發者俱樂部 十月份聚會

3. download the client lib

• # wget http://developers.new.facebook.com/clientlibs/facebook-platform.tar.gz

• # tar xvf facebook-platform.tar.gz

Page 44: funP 開發者俱樂部 十月份聚會

4. copy api key & secret

Page 45: funP 開發者俱樂部 十月份聚會

5. hello facebook

# vim facebook-platform/test.php

<?php

include_once(‘client/facebook.php’);$facebook = new Facebook( ‘<API_KEY>’, ‘<SECRET>’);$facebook->require_frame();$user = $facebook->require_login();echo ‘hello <fb:name uid=“’. $user.’“ useyou="false"/>’;

?>

Page 46: funP 開發者俱樂部 十月份聚會

Conclusion

Page 47: funP 開發者俱樂部 十月份聚會

Conclusion

• opportunities– existing users and connections– viral channels: feeds, requests, notifications

• difficulties– FBML, FBJS

Page 48: funP 開發者俱樂部 十月份聚會

marketplace

photos

feed

profile

group

users

auth

fql

money

pages

event

… …

Page 49: funP 開發者俱樂部 十月份聚會

<fp: ... />

Page 50: funP 開發者俱樂部 十月份聚會
Page 51: funP 開發者俱樂部 十月份聚會

Thank you

http://funp.com/