簡體   English   中英

使用facebook連接iPhone的上傳照片的記錄過程

[英]Documented process for using facebook connect for the iPhone to upload photos

看完之后我在facebook論壇上發了這篇文章:

鏈接

他們正在為Facebook對象提供UIImage。 這似乎合乎邏輯,但這在哪里記錄? API文檔推廣到所有平台。 iPhone對參數及其數據類型的具體要求在哪里?

謝謝

******更新*****我還沒有遇到任何與Cocoa有關的API文檔。 但是,我確實通過拼湊論壇信息,Facebook示例代碼和一些膠水來收集我需要的信息。

希望他們能在接下來的幾個月內發布更具體的內容。

為了完整性:

以下說明如何與Facebook Connect進行交互: https//developers.facebook.com/docs/guides/web/

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

如果您需要擴展權限: https//developers.facebook.com/docs/guides/policy/examples_and_explanations/Extended_Permissions/

Mobile Orchard上一個不錯的Obj-C包裝器: http//www.mobileorchard.com/marketing-in-code-part-2-setting-a-users-status-in-facebook-from-an-iphone-app-一個教程/

接下來是我對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

Joe Hewitt(Facebook iPhone應用程序的作者)發布了Facebook應用程序的大部分作為他的Three20框架。 它托管在github上

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM