0

我可以使用代码在朋友的墙上张贴图片

-(void)PostToBuddyWallWithText:(NSString *)strMessage
{
    NSMutableDictionary  *postVariablesDictionary = [[NSMutableDictionary alloc] init];

    [postVariablesDictionary setObject:@"100003146964353" forKey:@"from"];    
    [postVariablesDictionary setObject:strMessage forKey:@"message"];
    [postVariablesDictionary setObject:@"http://www.xyz.com/graphics/best-friends/best-friends24.gif" forKey:@"picture"];

    AppDelegate *objAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (objAppDelegate.objFacebook.isSessionValid == YES) 
    {
        [objAppDelegate.objFacebook requestWithGraphPath:[NSString stringWithFormat:@"%@/feed/",self.strfacebook_Id] andParams:postVariablesDictionary andHttpMethod:@"POST" andDelegate:nil];

        NSLog(@"message: %@",postVariablesDictionary);
        [postVariablesDictionary release];

        UIAlertView *facebookAlter=[[UIAlertView alloc] initWithTitle:@"Message" message:@"Posted successfully on facebook" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil, nil];
        [facebookAlter show];
        [facebookAlter release]; 
        [self dismissModalViewControllerAnimated:YES];    
    }  else {
            [objAppDelegate FacebookLogin];
    }   
}

但我无法找到将我拥有的图像作为 UIImage 发布的方法。这可以做到吗?

4

2 回答 2

0

实现 GarphAPI 和 ASIHTTPRequest 并使用下面的代码在朋友墙上发布带有图像的文本......

    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/photos?access_token=%@",[FRIEND_ID], fbGraph.accessToken];

    UIImage * pic = [UIImage imageNamed:@"image.png"];
    NSData *picData = UIImageJPEGRepresentation(pic, 1);
    NSURL *url = [NSURL URLWithString:urlString];
    ASIFormDataRequest *newRequest = [ASIFormDataRequest requestWithURL:url];
    [newRequest setPostValue:@"This is Sample Text" forKey:@"message"];
    [newRequest setData:picData forKey:@"data"];
    [newRequest setPostValue:fbGraph.accessToken forKey:@"access_token"];
    [newRequest setDelegate:self];
    [newRequest startAsynchronous];

这将作为 100% 的欢呼工作......我现在正在使用它......顺便将 FBGraph.h 和 ASIFormDataRequest.h 导入您的实现文件

于 2013-03-16T13:30:30.860 回答
0

用它来发布 UIImage

[postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"];
于 2012-11-26T07:40:53.360 回答