Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:36:24+00:00 2026-06-08T01:36:24+00:00

I have a problem with implementing Facebook posting on wall in my iPhone application.

  • 0

I have a problem with implementing Facebook posting on wall in my iPhone application.
I installed SDK and linked framework
login is working fine. here’s the code:

-(IBAction)loginButtonPressed:(id)sender
{
    NSLog(@"loginButtonPressed: called");

    AppDelegate *appdel=[[UIApplication sharedApplication] delegate];
    appdel.facebookSession=[[FBSession alloc] init];
    [appdel.facebookSession openWithCompletionHandler:^(FBSession *session, 
                                                     FBSessionState status, 
                                                     NSError *error)
    {
        //
    }];
}

But I have a problem with posting message on user’s wall. Here’s the code:

-(IBAction)likeButtonPressed:(id)sender
{
    NSLog(@"likeButtonPressed: called");
    // Post a status update to the user's feedm via the Graph API, and display an alert view 
    // with the results or an error.

    NSString *message = @"test message";
    NSDictionary *params = [NSDictionary dictionaryWithObject:message forKey:@"message"];

    // use the "startWith" helper static on FBRequest to both create and start a request, with
    // a specified completion handler.
    [FBRequest startWithGraphPath:@"me/feed"
                       parameters:params
                       HTTPMethod:@"POST"
                completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                    [self showAlert:message result:result error:error];
                }];

}

Help me please. What’s wrong with my code? Or should I add some permissions to login request?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:36:27+00:00Added an answer on June 8, 2026 at 1:36 am

    this code worked for me.
    First we must

    #import <FBiOSSDK/FacebookSDK.h>
    

    then

    @property (strong, nonatomic) FBRequestConnection *requestConnection;
    

    and of course do not forget to synthesize:

    @synthesize requestConnection;
    

    the code itself:

    -(IBAction)likeButtonPressed:(id)sender
    {
        NSLog(@"likeButtonPressed: called");
        // FBSample logic
        // Check to see whether we have already opened a session.
        if (FBSession.activeSession.isOpen)
        {
            // login is integrated with the send button -- so if open, we send
            [self postOnWall];
        }
        else
        {
            [FBSession sessionOpenWithPermissions:[NSArray arrayWithObjects:@"publish_stream", nil]
                                    completionHandler:
                 ^(FBSession *session, 
                   FBSessionState status, 
                   NSError *error)
                {
                     // if login fails for any reason, we alert
                     if (error)
                     {
                         NSLog(@"    login failed");
                         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                         message:error.localizedDescription
                                                                        delegate:nil
                                                               cancelButtonTitle:@"OK"
                                                               otherButtonTitles:nil];
                         [alert show];
                         // if otherwise we check to see if the session is open, an alternative to
                         // to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
                         // property of the session object; the macros are useful, however, for more
                         // detailed state checking for FBSession objects
                     }
                     else if (FB_ISSESSIONOPENWITHSTATE(status))
                     {
                         NSLog(@"    sending post on wall request...");
                         // send our requests if we successfully logged in
                         [self postOnWall]; 
                     }
                 }];
        };
    }
    
    - (void)postOnWall
    {
        NSNumber *testMessageIndex=[[NSNumber alloc] init];
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"testMessageIndex"]==nil)
        {
            testMessageIndex=[NSNumber numberWithInt:100];
        }
        else
        {
            testMessageIndex=[[NSUserDefaults standardUserDefaults] objectForKey:@"testMessageIndex"];
        };
        testMessageIndex=[NSNumber numberWithInt:[testMessageIndex intValue]+1];
        [[NSUserDefaults standardUserDefaults] setObject:testMessageIndex forKey:@"testMessageIndex"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    
        // create the connection object
        FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
    
        // create a handler block to handle the results of the request for fbid's profile
        FBRequestHandler handler =
        ^(FBRequestConnection *connection, id result, NSError *error) {
            // output the results of the request
            [self requestCompleted:connection forFbID:@"me" result:result error:error];
        };
    
        // create the request object, using the fbid as the graph path
        // as an alternative the request* static methods of the FBRequest class could
        // be used to fetch common requests, such as /me and /me/friends
        NSString *messageString=[NSString stringWithFormat:@"wk test message %i", [testMessageIndex intValue]];
        FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:[NSDictionary dictionaryWithObject:messageString forKey:@"message"] HTTPMethod:@"POST"];
    
        // add the request to the connection object, if more than one request is added
        // the connection object will compose the requests as a batch request; whether or
        // not the request is a batch or a singleton, the handler behavior is the same,
        // allowing the application to be dynamic in regards to whether a single or multiple
        // requests are occuring
        [newConnection addRequest:request completionHandler:handler];
    
        // if there's an outstanding connection, just cancel
        [self.requestConnection cancel];
    
        // keep track of our connection, and start it
        self.requestConnection = newConnection;    
        [newConnection start];
    }
    
    // FBSample logic
    // Report any results.  Invoked once for each request we make.
    - (void)requestCompleted:(FBRequestConnection *)connection
                     forFbID:fbID
                      result:(id)result
                       error:(NSError *)error
    {
        NSLog(@"request completed");
    
        // not the completion we were looking for...
        if (self.requestConnection &&
            connection != self.requestConnection)
        {
            NSLog(@"    not the completion we are looking for");
            return;
        }
    
        // clean this up, for posterity
        self.requestConnection = nil;
    
        if (error)
        {
            NSLog(@"    error");
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            // error contains details about why the request failed
            [alert show];
        }
        else
        {
            NSLog(@"   ok");        
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a strange problem when implementing sessions with ColdFusion in IE6. After login
I have complete code for implemention for facebook in my application But the problem
I have a slight problem implementing vibration functionality in my application. My code is:
I have a problem implementing Oauth in Android using signpost library. Everything is fine
I have problem with show or hide form in Window Form Application. I start
i have a little problem implementing some serialization/deserialization logic. I have several classes that
I have a problem with a command button (implementing the ICommand). I want, when
I'm implementing Google Maps service with PHP/CURL and currently have a problem with Maps
I'm implementing a Skein hash function in Java, and I have a problem with
I have a problem in implementing Mashups in PHP. Now I am using PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.