Facebook图形api与本机iPhone应用程序

时间:2010-06-18 22:50:43

标签: iphone facebook

我想在NATIVE iPhone应用程序中使用Facebook Graph API。有没有人能够找到一种方法在用户的Feed上发布图片/消息?

我已经尝试了所有可能的方式在Feed上发布“图片”(不是网址而是UII图片),并且已经在这上面工作了2周。

如果您访问facebook.com,您可以将计算机上的图片上传到墙上。我正在使用ASIHTTPRequest来处理facebook图形API。

这是我在Feed上发布图片的最近内容。所以,如果我有一个ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

网址为https://graph.facebook.com/me/feed

现在发布图片我会做以下事情:

[request setPostValue:@"My Message" forKey:@"message"];

[request setPostValue:@"somepic.png" forKey:@"picture"];

[request setPostValue:@"Some Name" forKey:@"name"];

[request setPostValue:@"Some description" forKey:@"description];

[request startAsynchronous];

如果您尝试这个,那么除了张贴的图片之外,一切正常。虽然在Feed上显示了图片的空白占位符。

1 个答案:

答案 0 :(得分:1)

我创建了一个方法来帮助我这样做。希望这有一些帮助。

请阅读有关如何设置Facebook SDK的教程。

-(void) updateStatusWithText:(NSString *) fbTitle //Status title
                 andStoryURL:(NSString *) fbURL   //URL for the story
                    andStory:(NSString *) fbStory //The story
                    andImage:(NSString *) imageURL //Image to be displayed.
                   andPrompt:(NSString *) promptString{

    NSLog(@"updateStatusWithText");

    NSString *attachmentText =[NSString stringWithFormat:@"{\"name\":\"%@\","
                               "\"href\":\"%@\","
                               "\"description\":\"%@\","
                               "\"media\":[{\"type\":\"image\","
                               "\"src\":\"%@\","
                               "\"href\":\"%@\"}],"
                               "\"properties\":{\"Uploaded from an iPhone\":{\"text\":\"AFL Fan\",\"href\":\"Your itunes apstore URL\"}}}", fbTitle, fbURL, fbStory,imageURL,fbURL];


    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    promptString,  @"user_message_prompt",

                                   //  actionLinksStr, @"properties",
                                   attachmentText, @"attachment",
                                   nil];
    NSLog (@"attachmentText : %@", attachmentText);


    [facebook dialog:@"stream.publish"
           andParams:params
         andDelegate:self];

}
相关问题