使用FBSDK 4.x for iOS在Facebook上发布图像

时间:2015-05-19 06:09:10

标签: ios xcode facebook facebook-sdk-4.0

对于新的Error in function () : non-numeric argument to binary operator,框架有了新的变化。它包括3个不同的框架,如

  • 核心
  • 共享
  • 登录。

分享我使用public HeartBeatBean getHBDetails(Double nidev) throws SQLException { HeartBeatBean hbBean = null; if(nidev > 0) { pstmt = con.prepareStatement("SELECT nidevid,hbtimestamp FROM nidhb where nidevid=? ORDER BY nidhbid"); try { pstmt.setDouble(1, nidev); rs = pstmt.executeQuery(); if(rs.next()) { hbBean = new HeartBeatBean(); rs.getTimestamp("hbtimestamp"); System.out.println(rs.getTimestamp("hbtimestamp")); hbBean.setHbtimestamp(rs.getTimestamp("hbtimestamp")); } } catch (SQLException ex) { System.err.println(ex.getMessage()); } 类的任何图像。但它有方法

CollectionType

我想将图片添加为字符串和文字。任何人都可以帮助我,所以我可以使用FB的新sdk发布图片标题。

先谢谢。

3 个答案:

答案 0 :(得分:7)

正如@NANNAV发布它会起作用,但是如果你想在任何FB Dialog屏幕上静默分享,那么使用" shareWithContent"如下所示,但您需要提交您的Facebook应用以供审核。

Obj-c中的代码

FBSDKSharePhoto *sharePhoto = [[FBSDKSharePhoto alloc] init];
sharePhoto.caption = @"Test Caption";
sharePhoto.image = [UIImage imageNamed:@"BGI.jpg"];

FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[sharePhoto];

[FBSDKShareAPI shareWithContent:content delegate:self];

Swift中的代码

var sharePhoto = FBSDKSharePhoto()
sharePhoto.caption = "Test"
sharePhoto.image = UIImage(named: "BGI.jpg")

var content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]

FBSDKShareAPI.shareWithContent(content, delegate: self)

答案 1 :(得分:5)

将标题字符串分配给标题键值

@property(非原子,复制)NSString *标题;

试试这个:

 FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
      photo.image = image;
      photo.userGenerated = YES;
    photo.caption = @"Add Your caption";
      FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
      content.photos = @[photo];
    [FBSDKShareDialog showFromViewController:self
                                 withContent:content
                                    delegate:nil];

答案 2 :(得分:2)

使用Facebook SDK 4.x添加以下代码以便将文本分享到Facebook

 FBSDKGraphRequestConnection *connection  =[[FBSDKGraphRequestConnection alloc]init];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Your_message_here_to_share_FB", @"message",
                               nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if(error){
           NSLog(@"Failed to share");
        }
    else{
           NSLog(@"Updated successfully");

        }

}];

*添加以下代码以分享照片。

FBSDKGraphRequestConnection *connection  =[[FBSDKGraphRequestConnection alloc]init];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: image, @"picture",
                               @"Your_text_here",@"message",
                               nil];

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"];

[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

    if(result)
    {
        NSLog(@"Posting the image is success, the result is%@",result);
    }
    else if(error)
    {
        NSLog(@"Error occured while posting image %@",error);
    }
}];

[connection start];