Uploading photo with caption or status to Facebook on iPhone app

后端 未结 2 1803
太阳男子
太阳男子 2020-12-15 02:01

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 phot

相关标签:
2条回答
  • 2020-12-15 02:20

    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];
    
    0 讨论(0)
  • 2020-12-15 02:22

    You can upload photo by using iOS Facebook SDK as follows:

        FBSDKSharePhoto *photo=[[FBSDKSharePhoto alloc]init];
        photo.image=slideImage;
    
        FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
        content.photos = @[photo];
    
        [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
    
    This works only if you configure iPhone Facebook settings.
    
    0 讨论(0)
提交回复
热议问题