-2

I want to post the image on a page wall and i know how to post the image on a album, and user feeds but for page its giving some issues

I am using the FBGraph API and want to upload a photo to a facebook page could you guide me for that by providing links to any tutorial or any code base.

Currently all the images that i post are being displayed in my wall and not the page to which i want to post.

I have used the below code

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

    //create a FbGraphFile object insance and set the picture we wish to publish on it
    UIImage *frontImageNew=self.imgvgalleryImage.image;

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

    //finally, set the FbGraphFileobject onto our variables dictionary....
    [variables setObject:graph_file forKey:@"file"];

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

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

    [variables 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 response = %@",facebook_response);

}

Am using the above code its posting the text successfully on the page wall but not the image

Radix
  • 3,639
  • 3
  • 31
  • 47

1 Answers1

0

You can do it by using ASIHTTPRequest.Try this its working for my code.

-(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);
}
mshau
  • 503
  • 4
  • 19
  • I am using exact code just one difference, I am using `facebook_PAGE_ID` at the place of `me`. But it seems that no matter what it posts on `me` only. are you aware of any such restriction or mis behavior of facebook api? – geekay Nov 02 '12 at 19:17