【问题标题】:iOS & Facebook: upload an image along with user comment to the walliOS 和 Facebook:将图片和用户评论一起上传到墙上
【发布时间】:2011-12-10 21:19:20
【问题描述】:

我有一个应用程序,它会自行截取屏幕截图,我想将它与评论一起发布到用户的墙上。

问题是,我似乎尝试了所有选项,但都不起作用:

  • [facebook dialog:@"feed" ...] 不起作用,因为您只能提供 URL,而不能提供 UIImage。

  • [facebook requestWithGraphPath ...] 不起作用,因为没有提示用户发表评论。

  • 我可以首先(默默地)尝试使用requestWithGraphPath 上传屏幕截图,然后将其新创建的 URL 提供给dialog,这不起作用,因为“流中不允许 FBCDN 图像”。当然,所有这些都是使用回调,包括登录回调,这会造成很大的混乱。

  • 我什至尝试过ShareKit,但在应用程序奇怪地可以/无法登录后忘记了它。

请问,如何同时分享图片和评论?

【问题讨论】:

    标签: ios facebook sharekit


    【解决方案1】:

    如果您使用的是 facebook 最新的 iOS SDK,请在 Hackbook 示例应用程序中查找 APICallsViewController.m 文件。有这个方法可以直接使用 UIImage 发布:

    /*
     * Graph API: Upload a photo. By default, when using me/photos the photo is uploaded
     * to the application album which is automatically created if it does not exist.
     */
    - (void) apiGraphUserPhotosPost {
        NSString *sourcePath = [[NSBundle mainBundle] resourcePath];
        NSString *file1 = [sourcePath stringByAppendingPathComponent:@"/MP1101frame1002.jpg"];
        UIImage *img = [[[UIImage alloc]initWithContentsOfFile:file1]autorelease];
    
        [self showActivityIndicator];
        currentAPICall = kAPIGraphUserPhotosPost;
        HackbookAppDelegate *delegate = (HackbookAppDelegate *) [[UIApplication sharedApplication] delegate]; 
    
        // Download a sample photo
        NSURL *url = [NSURL URLWithString:@"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"];
        NSData *data = [NSData dataWithContentsOfURL:url];
    //    UIImage *img  = [[UIImage alloc] initWithData:data];   //here you can insert your UIImage
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       yourMessageHere, @"message",  //whatever message goes here
                                       img, @"picture",   //img is your UIImage
                                       nil];
        [[delegate facebook] requestWithGraphPath:@"me/photos"
                              andParams:params
                          andHttpMethod:@"POST"
                            andDelegate:self];
    }
    

    【讨论】:

    • 是的,我知道如何上传图片,谢谢。但是要与图片一起发表评论?
    • 我刚刚编辑了我的答案以显示如何包含消息。它是:yourMessageHere,@"message"。 yourMessageHere 是 NSString。 "message" 是 params 字典的键。
    • “不起作用,因为没有提示用户发表评论” - 如果我想让用户写评论,我应该怎么做?我必须自己在 Cocoa 中实现提示还是有办法让 Facebook API 帮助我?
    • 您需要自己动手来提示用户获取消息。这种方式也更好,因为您可以选择向用户显示提示的方式。
    【解决方案2】:

    如果您还没有,您可能想在此地址尝试 ShareKit 的最新开发分支: https://github.com/Sharekit/Sharekit

    社区对规范版本进行了重大改进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 2012-01-12
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 2012-10-06
      • 2011-07-23
      相关资源
      最近更新 更多