Ios Facebook共享对话框不发布带有本地图像的故事
我正在尝试使用共享对话框发布一篇文章,代码如下:Ios Facebook共享对话框不发布带有本地图像的故事,ios,facebook-graph-api,Ios,Facebook Graph Api,我正在尝试使用共享对话框发布一篇文章,代码如下: [FBDialogs presentShareDialogWithOpenGraphAction:action actionType:@"myApp:myActionType" previewPropertyName:@"myObjectType"
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:@"myApp:myActionType"
previewPropertyName:@"myObjectType"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error)
{
if(error)
{
NSLog(@"Facebook: error publishing story: %@", error.description);
}
else
{
NSLog(@"Facebook: publishing story: result %@", results);
}
}];
我打开共享对话框(显示图像预览)并按Post
,然后我会看到进度条,但它没有进展,然后我会切换回我的应用程序。不仅如此,处理程序不会被调用。我试图发布一个带有本地生成图像的故事,如下所示:
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
NSArray* image = @[ @{@"url": [UIImage imageNamed:@"image-poof-1.png"], @"user_generated": @"true"} ];
[action setObject:image forKey:@"image"];
id<FBGraphObject> object = [FBGraphObject openGraphObjectForPost];
[object setObject:@"myApp:myObjectType" forKey:@"type"];
[object setObject:@"my title" forKey:@"title"];
[object setObject:@"my description" forKey:@"description"];
[action setObject:object forKey:@"myObjectType"];
id操作=(id)[FBGraphObject graphObject];
NSArray*image=@[@{@“url”:[UIImage ImageName:@“image-poof-1.png”],@“用户生成”:@“true”}];
[action setObject:image forKey:@“image”];
id对象=[FBGraphObjectOpenGraphObjectForPost];
[object setObject:@“myApp:MyObject类型”forKey:@“类型”];
[object setObject:@“我的标题”forKey:@“标题”];
[object setObject:@“我的描述”forKey:@“描述”];
[action setObject:object forKey:@“MyObject类型”];
我试着在网上用一个图片链接发帖,结果成功了
编辑:我遵循了我认为属性url只适用于图像url,请尝试发布文件:
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
UIImage *picture = [UIImage imageNamed:@"75x75.png"];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:@"file"];
[variables setObject:@"this is a test message: postPictureButtonPressed" forKey:@"message"];
//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"117795728310/photos" withPostVars:variables];
里德莫尔
我没有通过共享对话框发布本地图像的经验,但我在没有共享对话框的情况下将本地图像发布到facebook。并成功发布了图片和消息。我的代码是
NSString *message=@"your message";
UIImage *sendPic = [UIImage imageNamed:@"image.png"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:message forKey:@"message"];
[params setObject:UIImagePNGRepresentation(sendPic) forKey:@"picture"];
//fbShreBtn.enabled = NO; //for not allowing multiple hits
[FBSession setActiveSession:[self appDelegate].session];
[FBRequestConnection startWithGraphPath:@"me/photos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSLog(@"fb result : %@",result);
if (error)
{
//showing an alert for failure
NSLog(@"error : %@",error);
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
else
{
//showing an alert for success
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Post success"
message:@"Shared successfully"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
//fbShreBtn.enabled = YES;
}];
它可能对你有用。谢谢。Hm,我不确定这与发布故事有什么关系。我是SDK新手,我不知道如何将您提供的代码与文档建议的对象/操作对集成。您可以阅读示例项目:)此代码显示如何将图像发布到相册中,而不是如何将其与故事一起发布。抱歉!!我的错误你可以试试这个: