2

Using https://github.com/facebook/facebook-ios-sdk, how can I post a photo to a facebook fan page. And before it, how can let a user become a fan of the page (i.e. like)?

Even though I searched many web pages including stackoverflow, I couldn't find the way. Some answers said that it was not possible. But as you know, you can do these two things in the Facebook app.

[1] Post a post Just post a text is possible like the following code. 153120444748228 is a page id.

[_facebook requestWithGraphPath:@"153120444748228/feed"
     andParams:params
     andHttpMethod:@"POST"
     andDelegate:self];

But I tried to post a photo like above approach, the photo was posted on my wall instead.

NSString *path = @"http://php.chol.com/~sssang/zbxe/files/attach/images/12637/068/015/%ED%8B%B0%EC%95%84%EB%9D%BC-%EC%A7%80%EC%97%B0.jpg";
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img  = [[UIImage alloc] initWithData:data];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"Post a Picutre to a Fan Page", @"message",
                                   img, @"source",
                                   nil];

    // post a picutre to a page

    [_facebook requestWithGraphPath:@"153120444748228/photos"
                          andParams:params
                      andHttpMethod:@"POST"
                        andDelegate:self];

[2] Become a fan of a page. I tried to do it like the following, nothing happened. :(

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"http://www.facebook.com/pages/AlonesTest/153120444748228", @"url",
                               nil];

[_facebook requestWithGraphPath:@"153120444748228/likes"
                      andParams:params
                  andHttpMethod:@"POST"
                    andDelegate:self];
alones
  • 2,848
  • 2
  • 27
  • 30

1 Answers1

1

check my detailed answer here Posting photos to Facebook fan page with iOS SDK

You actually need to replace your faceBook accessToken with fanPage accessToken by

[_facebook setAccessToken:_accessTokenForFanPage];
Community
  • 1
  • 1
Arsalan
  • 150
  • 1
  • 11
  • Are you saying that all users of an app need to have the access token for the Fan Page in order to post to its timeline/wall? – mahboudz Feb 18 '12 at 06:39
  • Certainly no, Now there are two scenarios. 1. An owner of facebook fanpage. The above method will be used, because you need to authorize yourself as a page owner (you can create album etc) 2. A fan of facebook page. You can get likes (fan pages) of a user by requesting "me/likes" and post things like you post to walls of friend. (certainly you can not create albums). – Arsalan Feb 19 '12 at 14:33
  • What i am trying to do is to let any user of my app to post photos to the app's fan page. Right now I don't get errors, but the picture doesn't show up. – mahboudz Feb 20 '12 at 00:20