我想在没有 url 使用 FBWebDialogs 的情况下在 facebook 上共享应用程序包中的图像?
I want to share an image that is within the application bundle on facebook without url using FBWebDialogs?
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"The mechanic has done a fine job improving my vehicle…", @"name", @"Click below to download this awesome app for FREE and challenge me", @"description",iTunesLink, @"link", img, @"picture", nil];
//step 2
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
//nslog(@"Error publishing story.");
} else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
//nslog(@"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"])
{
// User clicked the Cancel button
//nslog(@"User canceled story publishing.");
} else
{
// User clicked the Share button
//NSString *msg = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
// Show the result in an alert
isSharedButtonTapped = YES;
self.btnFacebookShare.userInteractionEnabled = NO;
[[[UIAlertView alloc] initWithTitle:@"Success!" message:@"Successfully shared to Facebook" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
}
}
}
}];
如果我提供的图片是 "URL" 它 post 没问题。否则它的抛出错误。我想要 post 应用程序包中的图像。有人可以告诉我哪里编码错误吗?
你可以使用这样的东西
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
FBPhotoParams *params = [[FBPhotoParams alloc] init];
// Note that params.photos can be an array of images. In this example
// we only use a single image, wrapped in an array.
params.photos = @[img];
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
NSLog(@"Error: %@",
error.description);
} else {
NSLog(@"Success!");
}
}];
}
有关详细信息,您可以 check here。
但是,这会将共享图像添加到“照片”中,这不是您想要的方式。它将创建一个以应用程序名称命名的文件夹,图像将添加到该文件夹下。
`NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Sharing Tutorial", @"name",
@"Build great social apps and get more installs.", @"caption",
@"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description",
@"https://developers.facebook.com/docs/ios/share/", @"link",
@"http://i.imgur.com/g3Qc1HN.png", @"picture",
nil];`
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
} else {
//分享成功对话框
}
}];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"The mechanic has done a fine job improving my vehicle…", @"name", @"Click below to download this awesome app for FREE and challenge me", @"description",iTunesLink, @"link", img, @"picture", nil];
//step 2
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
//nslog(@"Error publishing story.");
} else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
//nslog(@"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"])
{
// User clicked the Cancel button
//nslog(@"User canceled story publishing.");
} else
{
// User clicked the Share button
//NSString *msg = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
// Show the result in an alert
isSharedButtonTapped = YES;
self.btnFacebookShare.userInteractionEnabled = NO;
[[[UIAlertView alloc] initWithTitle:@"Success!" message:@"Successfully shared to Facebook" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
}
}
}
}];
如果我提供的图片是 "URL" 它 post 没问题。否则它的抛出错误。我想要 post 应用程序包中的图像。有人可以告诉我哪里编码错误吗?
你可以使用这样的东西
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
FBPhotoParams *params = [[FBPhotoParams alloc] init];
// Note that params.photos can be an array of images. In this example
// we only use a single image, wrapped in an array.
params.photos = @[img];
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
NSLog(@"Error: %@",
error.description);
} else {
NSLog(@"Success!");
}
}];
}
有关详细信息,您可以 check here。
但是,这会将共享图像添加到“照片”中,这不是您想要的方式。它将创建一个以应用程序名称命名的文件夹,图像将添加到该文件夹下。
`NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Sharing Tutorial", @"name",
@"Build great social apps and get more installs.", @"caption",
@"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description",
@"https://developers.facebook.com/docs/ios/share/", @"link",
@"http://i.imgur.com/g3Qc1HN.png", @"picture",
nil];`
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
} else {
//分享成功对话框
}
}];