查看: 1465|回复: 0
打印 上一主题 下一主题

浅析iPhone平台下Facebook开发

[复制链接]

1602

主题

1

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
24658
精华
6

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-8-6 16:16:11 |只看该作者 |倒序浏览
下面简单总结下具体的开发流程
开发者最关心的应该是接口.

Facebook就是iPhone client 和后台通信的接口。其实所有的流程都包含在interface 的定义里面。
大致流程应该是:
Step 1: Login In

Step 2: Communication ( send request and handle resp*****e )

Step 3: Login Out
Step 1: Login In
首先,创建Facebook instance
Facebook* facebook = [[Facebook alloc] init];
在UI上,弹出

Button 实际会调用
- (void) authorizeNSString*) application_id

permissi*****NSArray*) permissi*****

delegateid) delegate;
参数说明:
application_id

创建自己的app id http://www.facebook.com/developers/createapp.php
permissi*****
比如

_permissi***** = [[NSArrayarrayWithObjects:

@"read_stream", @"offline_access",nil] retain];
delegate

负责login ,log out etc
/*

*Your application should implement this delegate

*/

@protocol FBSessionDelegate
@optional
/**

* Called when the dialog successful log in the user

*/

- (void)fbDidLogin;
/**

* Called when the user dismiss the dialog without login

*/

- (void)fbDidNotLoginBOOL)cancelled;
/**

* Called when the user is logged out

*/

- (void)fbDidLogout;
@end
Step 2: 和facebook 后台通信
让我们先来看看通信的api
- (void) requestWithParamsNSMutableDictionary *) params

andDelegateid ) delegate;
- (void) requestWithMethodNameNSString *) methodName

andParamsNSMutableDictionary *) params

andHttpMethodNSString *) httpMethod

andDelegateid ) delegate;
- (void) requestWithGraphPathNSString *) graphPath

andDelegateid ) delegate;
- (void) requestWithGraphPathNSString *)graphPath

andParams:(NSMutableDictionary *) params

andDelegate:(id ) delegate;
- (void) requestWithGraphPath:(NSString *)graphPath

andParams:(NSMutableDictionary *) params

andHttpMethod:(NSString *) httpMethod

andDelegate:(id ) delegate;
实际上这5个API 可以分为两个大类:
1, Old REST API
- (void) requestWithParams:(NSMutableDictionary *) params

andDelegate:(id ) delegate;
- (void) requestWithMethodName:(NSString *) methodName

andParams:(NSMutableDictionary *) params

andHttpMethod:(NSString *) httpMethod

andDelegate:(id ) delegate;
例子:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"4", @"uids", @"name", @"fields", nil]; [facebook requestWithMethodName: @"users.getInfo" andParams: params andHttpMethod: @"GET" andDelegate: self];
2, Graph API
- (void) requestWithGraphPath:(NSString *) graphPath

andDelegate:(id ) delegate;
- (void) requestWithGraphPath:(NSString *)graphPath

andParams:(NSMutableDictionary *) params

andDelegate:(id ) delegate;
- (void) requestWithGraphPath:(NSString *)graphPath

andParams:(NSMutableDictionary *) params

andHttpMethod:(NSString *) httpMethod

andDelegate:(id ) delegate;

比如
[facebook requestWithGraphPath"me" andDelegate:self]; // get information about the currently logged in user [facebook requestWithGraphPath"platform/posts" andDelegate:self]; // get the posts made by the "platform" page

[facebook requestWithGraphPath"me/friends" andDelegate:self]; // get the logged-in user's friends

还有一类很重要的API

Displaying Dialogs
- (void) dialog:(NSString *) action

andDelegate:(id) delegate;
- (void) dialog:(NSString *) action

andParams:(NSMutableDictionary *) params

andDelegate:(id ) delegate;
比如用户在 wall 上发消息
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: apiKey, @"api_key", nil]; [facebook dialog"stream.publish" andParams:params andDelegate:self];
Step 3 : Log out
这一切似乎很容易啊!

具体可以参考例子 DemoApp


This was written by admin. Posted on Monday, November 22, 2010, at 5:02 pm. Filed under Uncategorized. Bookmark the permalink. Follow comments here with the RSS feed.     Post a comment or leave a trackback. Edit this entry.

Post a Comment

Logged in as ADMIN. Log out?

COMMENT


? The TTModel Ecosystem Diagram
转自:http://www.cocoachina.com/bbs/read.php?tid=38864&fpage=2  

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-6-16 09:27 , Processed in 0.073326 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部