使用facebook connect for iPhone上传照片的文档化过程
看了之后,我在facebook论坛上看到了这篇帖子: 他们正在向facebook对象提供UIImage。这似乎是合乎逻辑的,但在哪里有记录?API文档适用于所有平台。iPhone对参数及其数据类型的具体要求在哪里 谢谢 ******更新***** 我仍然没有看到任何与Cocoa相关的API文档。然而,我确实通过拼凑论坛信息、Facebook示例代码和一些胶水收集了我需要的信息 希望他们能在接下来的几个月里发布一些更具体的东西。乔·休伊特(Facebook iPhone应用程序的作者)发布了Facebook应用程序的大部分内容作为他的Three20框架。它的主机位于。Joe Hewitt(Facebook iPhone应用程序的作者)发布了Facebook应用程序的大部分内容作为他的Three20框架。为完整起见,它位于。: 以下说明如何与Facebook Connect交互: API调用: 如果您需要扩展权限: Mobile Orchard上的漂亮Obj-C包装: 下面是我对SessionViewController的实现:使用facebook connect for iPhone上传照片的文档化过程,iphone,facebook,Iphone,Facebook,看了之后,我在facebook论坛上看到了这篇帖子: 他们正在向facebook对象提供UIImage。这似乎是合乎逻辑的,但在哪里有记录?API文档适用于所有平台。iPhone对参数及其数据类型的具体要求在哪里 谢谢 ******更新***** 我仍然没有看到任何与Cocoa相关的API文档。然而,我确实通过拼凑论坛信息、Facebook示例代码和一些胶水收集了我需要的信息 希望他们能在接下来的几个月里发布一些更具体的东西。乔·休伊特(Facebook iPhone应用程序的作者)发布了Fa
#import "SessionViewController.h"
#import "FBConnect.h"
#import "FBFeedDialog.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// This application will not work until you enter your Facebook application's API key here:
static NSString* kApiKey = @"XXXXXXXXXXXXXXXXXX";
// Enter either your API secret or a callback URL (as described in documentation):
static NSString* kApiSecret = @"XXXXXXXXXXXXXXXXXX"; // @"<YOUR SECRET KEY>";
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation SessionViewController
@synthesize label = _label;
@synthesize anImage;
- (void)done:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)init {
if (self = [super init]) {
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:@"SessionViewController" bundle:nibBundleOrNil]) {
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
}
return self;
}
- (void)dealloc {
[_session release];
[anImage release];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController
- (void)viewDidLoad {
[_session resume];
_loginButton.style = FBLoginButtonStyleWide;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBDialogDelegate
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error {
_label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
error.localizedDescription];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBSessionDelegate
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
_permissionButton.hidden = NO;
_feedButton.hidden = NO;
NSString* fql = [NSString stringWithFormat:
@"select uid,name from user where uid == %lld", session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}
- (void)sessionDidLogout:(FBSession*)session {
_label.text = @"";
_permissionButton.hidden = YES;
_feedButton.hidden = YES;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBRequestDelegate
- (void)request:(FBRequest*)request didLoad:(id)result {
if([result isKindOfClass:[NSArray class]]){
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:@"name"];
_label.text = [NSString stringWithFormat:@"Logged in as %@", name];
}
}
- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
_label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
error.localizedDescription];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (IBAction)askPermissionForPhotoUpload:(id)target {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"photo_upload";
[dialog show];
}
- (IBAction)publishPhoto:(id)target{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:self.anImage forKey:@"image"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:@"photos.upload" params:args];
}
- (void)askPermission:(id)target {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"status_update";
[dialog show];
}
- (void)publishFeed:(id)target {
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 9999999;
dialog.templateData = @"{\"key1\": \"value1\"}";
[dialog show];
}
@end
#导入“SessionViewController.h”
#导入“FBConnect.h”
#导入“FBFeedDialog.h”
///////////////////////////////////////////////////////////////////////////////////////////////////
//在此处输入Facebook应用程序的API密钥之前,此应用程序将无法工作:
静态NSString*kApiKey=@“xxxxxxxxxxxxxxxx”;
//输入API密码或回调URL(如文档中所述):
静态NSString*kApiSecret=@“XXXXXXXXXXXXXXXXXXXX”;//@"";
///////////////////////////////////////////////////////////////////////////////////////////////////
@实现SessionViewController
@综合标签=_标签;
@合成动物图像;
-(无效)完成:(id)发件人{
[自我解散Modalviewcontrolleranimated:是];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//NSObject
-(id)init{
if(self=[super init]){
_会话=[[FBSession sessionForApplication:kApiKey secret:kApiSecret委托:self]retain];
}
回归自我;
}
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{
if(self=[super initWithNibName:@“SessionViewController”bundle:nibBundleOrNil]){
_会话=[[FBSession sessionForApplication:kApiKey secret:kApiSecret委托:self]retain];
}
回归自我;
}
-(无效)解除锁定{
[_会话发布];
[动画发布];
[super dealoc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//UIViewController
-(无效)viewDidLoad{
[_会议恢复];
_loginButton.style=FBLoginButtonStyleWide;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
返回否;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//FBDialogDelegate
-(无效)对话框:(FBDialog*)对话框错误:(N错误*)错误{
_label.text=[NSString stringWithFormat:@“错误(%d)%@”,错误代码,
错误。本地化描述];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//FBSessionDelegate
-(void)会话:(FBSession*)会话登录:(FBUID)uid{
_permissionButton.hidden=否;
_feedButton.hidden=否;
NSString*fql=[NSString stringWithFormat:
@“选择uid,用户名称,其中uid==%lld”,session.uid];
NSDictionary*参数=[NSDictionary Dictionary WithObject:fql forKey:@“query”];
[[FBRequestRequestWithDelegate:self]调用:@“facebook.fql.query”params:params];
}
-(void)sessionIDLogout:(FBSession*)session{
_label.text=@;
_permissionButton.hidden=是;
_feedButton.hidden=是;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//FBRequestDelegate
-(void)请求:(FBRequest*)请求加载:(id)结果{
if([result iskindof class:[NSArray class]]){
NSArray*用户=结果;
NSDictionary*user=[users objectAtIndex:0];
NSString*name=[user objectForKey:@“name”];
_label.text=[NSString stringWithFormat:@“以%@”登录,名称];
}
}
-(无效)请求:(FBRequest*)请求失败错误:(NSError*)错误{
_label.text=[NSString stringWithFormat:@“错误(%d)%@”,错误代码,
错误。本地化描述];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-(iAction)askPermissionForPhotoUpload:(id)目标{
FBPermissionDialog*对话框=[[[FBPermissionDialog alloc]init]autorelease];
dialog.delegate=self;
dialog.permission=@“照片上传”;
[对话显示];
}
-(IBAction)publishPhoto:(id)目标{
NSMutableDictionary*args=[[NSMutableDictionary alloc]init]autorelease];
[args setObject:self.anImage forKey:@“image”];
FBRequest*uploadPhotoRequest=[FBRequestRequestWithDelegate:self];
[uploadPhotoRequest调用:@“photos.upload”参数:args];
}
-(void)askPermission:(id)目标{
FBPermissionDialog*对话框=[[[FBPermissionDialog alloc]init]autorelease];
dialog.delegate=self;
dialog.permission=@“状态\更新”;
[对话显示];
}
-(void)publishFeed:(id)目标{
FBFeedDialog*dialog=[[[FBFeedDialog alloc]init]autorelease];
dialog.delegate=self;
dialog.templateBundleId=999999;
dialog.templateData=@“{\“key1\”:\“value1\”}”;
[对话显示];
}
@结束
完整性:
以下说明如何与Facebook Connect交互:
API调用:
如果您需要扩展权限:
Mobile Orchard上的漂亮Obj-C包装:
下面是我对SessionViewController的实现:
#import "SessionViewController.h"
#import "FBConnect.h"
#import "FBFeedDialog.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// This application will not work until you enter your Facebook application's API key here:
static NSString* kApiKey = @"XXXXXXXXXXXXXXXXXX";
// Enter either your API secret or a callback URL (as described in documentation):
static NSString* kApiSecret = @"XXXXXXXXXXXXXXXXXX"; // @"<YOUR SECRET KEY>";
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation SessionViewController
@synthesize label = _label;
@synthesize anImage;
- (void)done:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)init {
if (self = [super init]) {
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:@"SessionViewController" bundle:nibBundleOrNil]) {
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
}
return self;
}
- (void)dealloc {
[_session release];
[anImage release];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController
- (void)viewDidLoad {
[_session resume];
_loginButton.style = FBLoginButtonStyleWide;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBDialogDelegate
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error {
_label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
error.localizedDescription];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBSessionDelegate
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
_permissionButton.hidden = NO;
_feedButton.hidden = NO;
NSString* fql = [NSString stringWithFormat:
@"select uid,name from user where uid == %lld", session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}
- (void)sessionDidLogout:(FBSession*)session {
_label.text = @"";
_permissionButton.hidden = YES;
_feedButton.hidden = YES;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBRequestDelegate
- (void)request:(FBRequest*)request didLoad:(id)result {
if([result isKindOfClass:[NSArray class]]){
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:@"name"];
_label.text = [NSString stringWithFormat:@"Logged in as %@", name];
}
}
- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
_label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
error.localizedDescription];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (IBAction)askPermissionForPhotoUpload:(id)target {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"photo_upload";
[dialog show];
}
- (IBAction)publishPhoto:(id)target{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:self.anImage forKey:@"image"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:@"photos.upload" params:args];
}
- (void)askPermission:(id)target {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"status_update";
[dialog show];
}
- (void)publishFeed:(id)target {
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 9999999;
dialog.templateData = @"{\"key1\": \"value1\"}";
[dialog show];
}
@end
#导入“SessionViewController.h”
#进口“FB