Question

I am trying to make my app interact with Facebook. I am using their Facebook iOS SDK (3.0) and Xcode 4.2. So far I implemented a login method which also asks for the appropriate permissions for my app. This method is called when i click a button from a view controller, the method being located in the app delegate. Now what i want after the login is to post a photo to the users wall ; the view controller in which this button resides is a photo viewer and thus i have the image at hand. My problems that every method that I have seen to post an image to the wall includes having a Facebook type object in the app delegate. For this to be possible, you need to import Facebook.h, which is deprecated and manually adding it to the project so it can be imported causes a lot of errors. So how can I do this? How do you declare this Facebook object with the deprecated header? Or can you do it without the Facebook object in the new SDK?


Ok. So i partially solved it with this:

        - (void)facebookButtonHit:(id)sender{
  DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
      [appDelegate openSessionWithAllowLoginUI:YES];
    if(FBSessionStateOpen){ NSString *linkul=@"";
    NSString *captt=@"";
        //seteaza link-ul postului
    if([self.optiune isEqualToString:@"SETURI TEMATICE"]){
       linkul=@"http://www.calinevents.com/seturi.html";}
        captt=@"SET TEMATIC CALIN EVENTS MODEL ";
        NSInteger i=_pageIndex+1;
        NSString *mno=[NSString stringWithFormat:@"%i",i];
        captt= [captt stringByAppendingString:mno];
        //seteaza parametrii postului
     NSString *Path1 = [[NSBundle mainBundle] bundlePath];
     NSString *Datele1 = [Path1 stringByAppendingPathComponent:@"Seturi.plist"];
     NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:Datele1];
    NSDictionary *tempdicty=[[tempDict objectForKey:@"Rows"] objectAtIndex:_pageIndex];
            NSString *tempurl=[tempdicty objectForKey:@"URL"];
    NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
     linkul, @"link",
     tempurl, @"picture",
     @"Imi place acest produs Calin Events", @"name",
     captt, @"caption",
     @"     ",@"description",
     nil];

        //posteaza pe Facebook
    UIAlertView *incarcare=[[UIAlertView alloc] initWithTitle:@""
                                message:@"Se publica imaginea...\nVa rugam asteptati"
                               delegate:self
                      cancelButtonTitle:nil
                      otherButtonTitles:nil];
    [incarcare setBackgroundColor:[UIColor blackColor]];
    [incarcare show];
    [FBRequestConnection
     startWithGraphPath:@"me/feed"
     parameters:postParams
     HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection,
                         id result,
                         NSError *error) {
         NSString *alertText;
         if (error) {
             alertText = [NSString stringWithFormat:
                          @"S-a produs o eroare!\n Va rugam incercati din nou.",
                          error.domain, error.code];
         } else {
             alertText = [NSString stringWithFormat:
                          @"Imaginea a fost postata cu succes!\n Va multumim!",
                          [result objectForKey:@"id"]];
         }
         // Show the result in an alert

         [[[UIAlertView alloc] initWithTitle:@""
                                     message:alertText
                                    delegate:self
                           cancelButtonTitle:@"OK!"
                           otherButtonTitles:nil]
          show];
         [incarcare dismissWithClickedButtonIndex:0 animated:YES];
     }];
    }
}

But now i get the following error. First time this action is called , it gives an error code =5 , HTTP status code =400; the next time the button is hit, it works and the image gets posted along with all the info correctly. The next time the button is hit, it outputs the error again, the next time it publishes correctly. And so it goes error,publish,error,publish etc. What can I do to solve this?

Was it helpful?

Solution

I changed the first few lines of the code to this, and now it's OK:

DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
   if(![FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:YES];
                                            }
    if([FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:NO];}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top