【问题标题】:How to post image to facebook wall with graph api如何使用图形 api 将图像发布到 facebook 墙上
【发布时间】:2023-03-30 00:15:01
【问题描述】:

我想在 facebook 墙上发布一些带有图像的文本。我有这个来自 graph api 的代码,但我想从 bundle 发布我的图像,而不是像这个 api 那样从链接发布。谁能告诉我如何发布您自己的图片,而不是链接“[variables setObject:@"http://bit.ly/bFTnqd" forKey:@"link"];"在脸书墙上。

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"this is a test message: postMeFeedButtonPressed" forKey:@"message"];

UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];

[variables setObject:@"http://bit.ly/bFTnqd" forKey:@"link"];
[variables setObject:@"This is the bolded copy next to the image" forKey:@"name"];
[variables setObject:@"This is the plain text copy next to the image.  All work and no play makes Jack a dull boy." forKey:@"description"];



FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];   
[parser release];

//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:@"id"];
NSLog(@"feedPostId, %@", feedPostId);
NSLog(@"Now log into Facebook and look at your profile...");

【问题讨论】:

    标签: iphone api facebook-graph-api http-post


    【解决方案1】:

    您将图像转换为数据并将其作为另一个参数(键“数据”的数据值)添加到字典中。我在这里给出了示例

    [variables setObject:imageData forKey:@"data"];
    

    其他变化

    UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];
    
    NSData *imageData = UIImageJPEGRepresentation(picture, 10);
    
    
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"your caption message",@"message", 
                                   imageData,@"data",
                                   nil];
    
    FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables];
    NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);
    

    【讨论】:

    • 我试过你的代码,但它给出错误“-[NSConcreteMutableData dataUsingEncoding:]: unrecognized selector sent to instance 0x70c09e0”
    • 你想要所有的消息、描述、链接、所有这些字段还是只有带有标题的图像
    • 还有你是否增加了字典容量,NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:5];
    • 我没有增加容量,因为我删除了链接部分并添加了您的数据代码
    • 抱歉,它给出了错误“-[NSConcreteMutableData dataUsingEncoding:]: unrecognized selector sent to instance 0x70c09e0”并崩溃
    【解决方案2】:

    以下代码应该可以解决您的问题...

        FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
        dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Photo uploaded.\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"\",\"href\":\"%@/\"}]}",PhotoSourceURL];
        [dialog show];
    

    告诉我,它对你有用吗...

    编辑:

    Try this one...

    【讨论】:

    • 这是来自 fbconnect 但我想使用图形 api
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    相关资源
    最近更新 更多