-2

我想将图像发布在页面墙上,并且我知道如何将图像发布到相册和用户提要上,但是对于页面它会给出一些问题

我正在使用 FBGraph API 并希望将照片上传到 facebook 页面,您能否通过提供任何教程或任何代码库的链接来指导我。

目前我发布的所有图像都显示在我的墙上,而不是我要发布的页面。

我使用了下面的代码

-(void)postPictureToWall
{
    NSMutableDictionary *variables = [[NSMutableDictionary alloc] init];

    //创建一个 FbGraphFile 对象实例并设置我们希望在其上发布的图片
    UIImage *frontImageNew=self.imgvgalleryImage.image;

    FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:frontImageNew];

    //最后,将 FbGraphFile 对象设置到我们的变量字典中......
    [变量 setObject:graph_file forKey:@"file"];

    NSDateFormatter *df = [[NSDateFormatter alloc]init];
    [df setDateStyle:NSDateFormatterMediumStyle];
    [df setTimeStyle:NSDateFormatterMediumStyle];

    NSString *bodyString=[NSString stringWithFormat:@"%@",[df stringFromDate:[NSDate date]]];

    [变量 setObject:bodyString forKey:@"message"];

 FbGraphResponse *fb_graph_response = [objFBGraph doGraphPost:@"pageid_here/feed" withPostVars:variables];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];   
    NSLog(@"fb 响应 = %@",facebook_response);

}

我正在使用上面的代码在页面墙上成功发布文本但不是图像

4

1 回答 1

0

您可以使用 ASIHTTPRequest 来实现。试试这对我的代码有效。

-(IBAction)shareClicked:(id)sender {

//    if (selectedImage) {
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Social Plus"
//                                                       message:@"Please select an image to share"
//                                                      delegate:self
//                                             cancelButtonTitle:@"OK"
//                                             otherButtonTitles:nil];
//        [alert show];
//    }
//    else {
//        

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"f_selected" ofType:@"png"];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me/photos"]];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    request.delegate = self;
    [request addFile:filePath forKey:@"file"];
    [request setPostValue:@"here will be the caption" forKey:@"message"];
    [request setPostValue:[[NSUserDefaults standardUserDefaults]objectForKey:@"access_token"] forKey:@"access_token"];
    [request setAllowCompressedResponse:NO];
//    [request setTimeOutSeconds:60];

    [request setDidFinishSelector:@selector(uploadRequestFinished:)];
    [request startAsynchronous];
//    }
}

-(void)uploadRequestFinished:(ASIHTTPRequest *)request
{

    NSString *responseStr = [request responseString];
    NSLog(@"%@",responseStr);
}
于 2012-06-20T10:14:06.817 回答