我正在尝试使用包含以下代码的共享对话框发布故事:
[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"];
我尝试使用指向网络上图片的链接进行发布,这很有效。
编辑:我已关注this facebook code example答案 0 :(得分:0)
我认为属性网址仅用于图片网址,只能尝试帖子文件:
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];
Readmore
答案 1 :(得分:0)
我没有使用分享对话框来发布本地图像,但我已将本地图像发布到没有共享对话框的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;
}];
它可能对您有用。感谢。