Search code examples
iosfacebookpostfacebook-wall

going crazy - how to set up an fb-app so my iOS-App can post to it's wall?


Ok, I know how to post to a USER's wall (timeline?), that works well.

What I want is when the user does certain things on his iPhone, that should appear as a post on the APP's wall. The post should be in the USER's name.

Something like:

Lucky Luke says: hi everybody

Zaphod Beeblebrox started using Awesomeapp

PLUS: only users of the app should be able to post to the app's wall (I saw the settings on the page's «Manage Permissions»-part where I can set who can post to the wall. I don't want everybody to make posts)

If I'm right, that post would automatically appear in the user's feed, too, wouldn't it? Or do I have to make a second post to the user's wall?

I request the following permissions when a user first uses the app: @"user_photos",@"user_videos", @"manage_pages",@"read_stream", @"publish_stream",@"user_checkins",@"friends_checkins",@"email",@"user_location"

(recently added the read_stream and manage_pages as I read that somewhere - didn't help, though :)

This is the piece of code I use to make the post:

NSString *graphPath = [NSString stringWithFormat: @"/%@/feed?access_token=%@", FBAppID, [FBAccessToken stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
    NSLog(@"graph path %@", graphPath);
    NSDictionary *postParams =
    @{
        @"Test": @"message"
    };


    [FBRequestConnection
     startWithGraphPath:graphPath
     parameters:postParams
     HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection,
                         id result,
                         NSError *error) {

         if (error) {
             NSLog(@"error: domain = %@, code = %d, %@",
                          error.domain, error.code, error.description);
         } else {
             NSLog(@"Posted action, id: %@",
                          [result objectForKey:@"id"]);
         }
         // Show the result in an alert
     }];

Which returns an error 100 (Missing message or attachment - OAuthException)

I googled like two days now and couldn't find any appropriate guidelines... HELP!!! :)

[Edit] I might be on to something...

Seems like the NSDictionary *postParams @{@"Test": @"message"}; was the problem. When I used the proper [[NSDictionary alloc] initWithObjectsAndKeys: ...]; it seems to work... we'll see :)

[Edit] Ok - I should take a break, it seems...

initializing a dictionary with @{...} requires the key first and then the object, vs [NSDictionary dictionaryWithObjectsAndKeys:...] which sets the object first and then the key...

I feel kinda stupid right now...


Solution

  • this is how i do this in my code:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My app's name", @"name",
                                   @"Some cool caption", @"caption",
                                   @"Super description", @"description",
                                   @"http://stackoverflow.com//", @"link",
                                   nil];
    
    
    [FBRequestConnection startWithGraphPath:@"me/feed"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    
           .....
     }];
    

    Please notice the GraphPath, it is a little bit different than yours. Also in my Info.plist there is a facebookId value:

    <key>FacebookAppID</key>
    <string>123456789876543</string>
    

    and facebook url scheme:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb123456789876543</string> (fb + your app id)
            </array>
        </dict>
    </array>
    

    and i have facebookSDK added to the project (i think you did this already)

    so this stuff is enough for me to post to my wall at least

    so please take a look of your facebookAppID, maybe there is something in it, and just in case this is the official facebook tutorial