簡體   English   中英

我可以使用UIImage在Facebook的朋友牆上張貼圖像嗎

[英]Can I post image on friend's wall on facebook using UIImage

我可以使用代碼在朋友的牆上張貼圖片

-(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發布的方法。 能做到嗎?

用它來發布UIImage

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

實現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導入您的實現文件中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM