【问题标题】:How to do wall post on facebook with image stored on iPhone?如何使用存储在 iPhone 上的图像在 Facebook 上进行墙贴?
【发布时间】:2011-05-12 05:27:47
【问题描述】:


我有一个应用程序,我必须在 facebook 的墙上发布图像。
现在的问题是我使用了 GraphAPI facebook,我必须传递照片的链接,但我的 iPhone 中有照片,而不是任何服务器上。
那么如何在没有图像 URL 的情况下发布带有图像和其他参数的墙呢?

【问题讨论】:

  • 可能重复:123456&c.
  • 我的实际问题与所有这些不同......
  • 我知道如何在相册中上传照片,我知道如何做墙贴..但是如何用本地图片而不是 URL 来做墙贴,URL 包含所有参数,如描述、链接、消息、等等。

标签: iphone facebook facebook-graph-api


【解决方案1】:

您可以使用 NSURLConnection ASIHttpRequest 库从 url 下载图像。

You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];

【讨论】:

    【解决方案2】:
    FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.userMessagePrompt = @"Enter your message:";
    
    NSDictionary *params = nil;
    [[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
    [dialog show];
    

    【讨论】:

      【解决方案3】:

      编辑:

      --

      实际上,将图片发布到 Facebook 墙上必须来自网络。所以你必须先上传图片;也许尝试第三方服务,如 twitpic 之类的,返回响应网址并将其放入您的参数中。

      --

      您可以使用以下方法将图片发布到 Facebook。您也可以将UIImage 替换为物理 URL。

      NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     kAppID, @"app_id",
                                     @"http://bit.ly/dDZQXt", @"link",
                                     @"www.has.to.be.web.based.com", @"picture",
                                     EasyStrings(@"Mobile Profiles for ",device), @"name",
                                     EasyStrings(@"Current Profile: ",currProfile), @"caption",
                                     @"I am using Mobile Profiles for iPhone, iPod touch and iPad.", @"description",
                                     message,  @"message",
                                     nil];
      [_facebook dialog:@"feed"
              andParams:params
            andDelegate:self];
      

      它会是什么样子:

      房子图标是从[UIImage imageNamed:@"something.png"]加载的。

      【讨论】:

        【解决方案4】:

        我修改了 facebook 演示应用程序。它使用模态视图从手机中选择图片。您可以使用此代码,前提是您必须添加两个按钮(即,selectPicture 按钮和一个 uploadPhoto 按钮)——也请务必在 .h 文件中添加到 UIViewController:

        /**
         * Upload a photo.
         */
        - (IBAction)uploadPhoto:(id)sender {
        
          NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         image, @"picture",
                                         nil];
        
          [_facebook requestWithGraphPath:@"me/photos"
                                andParams:params
                                andHttpMethod:@"POST"
                                andDelegate:self];
        
        }
        
        /**
         * Select a photo.
         */
        - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
        {
            image = [info objectForKey:UIImagePickerControllerOriginalImage];
            [self dismissModalViewControllerAnimated:YES];
        }
        
        - (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
        {
            [self dismissModalViewControllerAnimated:YES];
        }
        
        - (IBAction) selectPicture:(UIButton *)sender;
        {
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            [self presentModalViewController:picker animated:YES];
            [picker release];
        }
        

        【讨论】:

          【解决方案5】:

          尝试使用BMSocialShare,这是我编写的一个简单的库。它正是在做你想做的事。上传一些本地图片(甚至打开对话框供用户添加评论)到用户墙:

          BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
          [[BMSocialShare sharedInstance] facebookPublish:post];
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-12-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多