【问题标题】:Documented process for using facebook connect for the iPhone to upload photos使用 facebook connect for iPhone 上传照片的记录过程
【发布时间】:2009-04-15 04:39:12
【问题描述】:

看了之后,我确实在 facebook 论坛上看到了这篇文章:

link

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

谢谢

******更新***** 我仍然没有遇到任何与 Cocoa 有关的 API 文档。不过,我确实通过拼凑论坛信息、Facebook 示例代码和一些胶水来收集我需要的信息。

希望他们能在接下来的几个月里发布一些更具体的内容。

【问题讨论】:

    标签: iphone facebook


    【解决方案1】:

    为了完整性:

    下面解释了如何与 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-a-tutorial/

    以下是我对 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
    

    【讨论】:

      【解决方案2】:
      【解决方案3】:

      Joe Hewitt(Facebook iPhone 应用程序的作者)发布了 Facebook 应用程序的大部分内容作为他的 Three20 框架。它托管在github

      【讨论】:

      • 我已经看到了,但我专门讨论的是 iPhone Facebook Connect 库。这些不是关于向方法提供哪些数据类型的任何文档。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多