我可以使用UIImage在Facebook的朋友的墙上发布图像

时间:2012-11-26 07:38:03

标签: iphone objective-c ios xcode

我可以使用代码

在朋友的墙上发布图像
-(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的图像的方法。可以这样做吗?

2 个答案:

答案 0 :(得分:0)

用它来发布UIImage

[postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"];

答案 1 :(得分: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导入您的实现文件