在iPhone应用程序上将图片标题或状态上传到Facebook [英] Uploading photo with caption or status to Facebook on iPhone app

查看:90
本文介绍了在iPhone应用程序上将图片标题或状态上传到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法在iPhone应用程序上实现了Facebook连接,并允许用户通过该应用上传状态更新。我现在想包括一个功能,允许上传照片与标题或状态更新。有人知道相关的代码吗?



我想我应该在FB中使用photos.upload API,但不太确定如何。 Facebook文档似乎非常通用,没有特定的iPhone开发代码。

解决方案

以下代码摘自 facebook-ios-sdk 。假设你的课程已经有一个Facebook对象,这个方法将会从一个URL上传照片(根据需要进行更改):

   - ( IBAction)uploadPhoto:(id)sender {
NSString * path = @http://www.facebook.com/images/devsite/iphone_connect_btn.jpg;
NSURL * url = [NSURL URLWithString:path];
NSData * data = [NSData dataWithContentsOfURL:url];
UIImage * img = [[UIImage alloc] initWithData:data];

NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img,@picture,
nil];
[Facebook requestWithMethodName:@photos.upload
andParams:params
andHttpMethod:@POST
andDelegate:self];
[img release];
}

为了发送带有照片的标题,您必须添加消息参数键后跟字幕文本。更改 params 如下所示:

  NSMutableDictionary * params = [ NSMutableDictionary dictionaryWithObjectsAndKeys:
img,@picture,
@我的照片的标题文字在这里,@message
nil];


I managed to implement Facebook connect on my iPhone app and allow the user to upload a status update via the app. I now want to include a feature to allow uploading of photos together with a caption or status update. Does anyone know the relevant code for this?

I think I'm supposed to use the photos.upload API in FB but am not too sure how. The Facebook documentation all seems very generic with no specific code for iPhone development. Any assistance or sample code with be appreciated.

解决方案

This following snippet is taken from the facebook-ios-sdk. Assuming your class already has a facebook object, this method will upload a photo from a URL (change as needed):

-(IBAction) uploadPhoto: (id)sender {
  NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
  NSURL *url = [NSURL URLWithString:path];
  NSData *data = [NSData dataWithContentsOfURL:url];
  UIImage *img = [[UIImage alloc] initWithData:data];

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                  img, @"picture",
                                  nil];
  [facebook requestWithMethodName: @"photos.upload"
                         andParams: params
                     andHttpMethod: @"POST"
                       andDelegate: self];
  [img release];
}

In order to send a caption with the photo you must add the "message" parameter key followed by the caption text. Changing params like below should achieve this:

NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                img, @"picture", 
                @"my photo's caption text here.", @"message"
                                nil];

这篇关于在iPhone应用程序上将图片标题或状态上传到Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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