记录使用Facebook连接iPhone进行上传照片的过程 [英] Documented process for using facebook connect for the iPhone to upload photos

查看:117
本文介绍了记录使用Facebook连接iPhone进行上传照片的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看完后,我在Facebook论坛上发贴了这篇文章:

After looking I did come accross this post on the facebook forums:

链接

他们正在向facebook对象提供UIImage。这似乎是合乎逻辑的,但这里记录在哪里? API文档通用于所有平台。 iPhone的参数和数据类型的具体要求在哪里?

They are feeding the facebook object a UIImage. That seems logical, but where is this documented? The API documentation is generalized to all platforms. Where are the iPhone specific requirements for arguments and their data types?

谢谢

******更新*****
我还没有遇到任何有关Cocoa的API文档。然而,我已经收集了我所需要的信息,将论坛信息,Facebook示例代码和一些胶水拼凑在一起。

******Update***** I still have not came across any API docs pertaining to Cocoa. I did, however, gather the information I needed by piecing together forum information, Facebook sample code, and some glue.

希望他们会发布一些更具体的东西未来几个月。

Hopefully they'll issue something a little more concrete over the next few months.

推荐答案

为了完整性:

以下解释如何与Facebook Connect进行交互:
https://developers.facebook.com / docs / guides / web /

The following explains how to interact with Facebook Connect: https://developers.facebook.com/docs/guides/web/

API调用:
https://developers.facebook.com/docs/reference/api/

如果你需要扩展权限:
https://developers.facebook.com /文档/指南/策略/ examples_and_explanations / Extended_Permissions /

If you need extended Permissions: https://developers.facebook.com/docs/guides/policy/examples_and_explanations/Extended_Permissions/

移动果园上的一个漂亮的Obj-C包装:
http://www.mobileorchard.com/marketing-in-code-part- 2-setting-a-users-status-in-facebook-from-an-iphone-app-a-tutorial /

A nice Obj-C wrapper on Mobile Orchard: http://www.mobileorchard.com/marketing-in-code-part-2-setting-a-users-status-in-facebook-from-an-iphone-app-a-tutorial/

接下来是我的实现的一个SessionViewController:

What follows is my implementation of a 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

这篇关于记录使用Facebook连接iPhone进行上传照片的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆