20

I have the following page I want to show in facebook app: http://www.facebook.com/mypage

I try to do the following but it doesn't seem to work:

    NSURL *urlApp = [NSURL URLWithString:@"fb://profile/mypage"];
    [[UIApplication sharedApplication] openURL:urlApp];

also I tried @"fb://mypage" with the same negative result. Application is open but without the page needed.

Alexey
  • 7,127
  • 9
  • 57
  • 94

6 Answers6

46

To open facebook page in facebook app you should:

1)Find uid of your page (it can be done for example by looking at source code of your facebook page)

I got the following fragment from the source code of the page: http://www.facebook.com/yourpage

{"text":"yourpage","type":"ent:page","uid":****123****}

N.B.: To check if uid is correct substitute uid for pagename: http://www.facebook.com/****123**** This url should open your page.

2) When the uid is found and is correct use this code:

NSURL *urlApp = [NSURL URLWithString:@"fb://profile/****123****"];
[[UIApplication sharedApplication] openURL:urlApp];

This code will open you page within facebook app. N.B.: Do not forget to check if the facebook app exists( or more precisely that the url can be opened) using: if ([[UIApplication sharedApplication] canOpenURL:urlApp]) otherwise open it in Safari.

Alexey
  • 7,127
  • 9
  • 57
  • 94
  • i found the page number with the tag "profile_owner", not uid. – hariseldon78 Apr 18 '13 at 00:20
  • It doesn't look like FB puts the UID in the source any more, or if they do, it's not called out nicely like this. I found it more easily by right clicking on the profile picture, Copy Link, and grab the last set of numbers in that URL -- after a '.' If you prefer to find it in code, boz method is the best way to go. – Bek Jul 05 '13 at 12:07
  • 4
    a MUCH easier way of getting the UID would be to navigate to the page that you want a UID for and go up in to your address bar in your browser and change the `www` to `graph` – MrTristan May 30 '14 at 16:13
21

Another quick method is to use the facebook graph API e.g

https://graph.facebook.com/name-of-your-page-here

I used this to find the leeds uni page like so:

https://graph.facebook.com/universityofleeds

The results were as shown below, the id is the first element (highlighted) results of the facebook graph call

You will use it in your application like so

    NSURL *url = [NSURL URLWithString:@"fb://profile/93693583250"];
    [[UIApplication sharedApplication] openURL:url];
Edwin
  • 3,812
  • 2
  • 21
  • 16
5

Another method I found that works without having to do two different URL's depending on if FB app is installed. Will load in Safari fine if FB app is not installed, but uses FB app if it is.

https://www.facebook.com/your-facebook-page-id (id, not name)

And you can find your ID even easier these days by just hitting Edit Page, and going to "Page Info" tab, it's at the bottom.

Note: This does not work if you use your page name, must be page ID for some reason for the FB app to load it properly.

Michael
  • 435
  • 4
  • 9
0

I found this website that gets you the page ID quickly using page URL, i tried a lot of ways to get a page that i doesn't own but i failed, this one is cool :

https://findmyfbid.com/

then it will look like the below code:

NSURL *url = [NSURL URLWithString:@"fb://profile/Page_ID"];


[[UIApplication sharedApplication] openURL:url];
Mostafa Sultan
  • 2,268
  • 2
  • 20
  • 36
-3

Try this

NSURL *urlApp = [NSURL URLWithString:@"http://www.facebook.com/Innova.et.Bella"];
[[UIApplication sharedApplication] openURL:urlApp];
fibnochi
  • 1,113
  • 1
  • 9
  • 26
-3

Use this:

NSURL *urlApp = [NSURL URLWithString:@"http://www.facebook.com/yourpage"];

UIApplication *app = [UIApplication sharedApplication];

[app openURL:urlApp];
Alexey
  • 7,127
  • 9
  • 57
  • 94
Mudit Bajpai
  • 3,010
  • 19
  • 34
  • 1
    Your code will open the page with Safari, but I need to open the page within app Facebook. – Alexey Jan 24 '12 at 11:37