Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if Facebook app is on a page?

The approach I've been using initially was:

http_head('http://www.facebook.com/pages/Test/' . $input['fb_page_id'] . '?sk=app_' . $input['fb_id']), 'HTTP/1.1 301 Moved Permanently')

The problem with this approach is:

  1. If the page doesn't exist at all, Facebook will return 200 header, rather than 404 (eg. http://www.facebook.com/pages/Test/DominosPizza?sk=app_311706258843058).
  2. If page has a username, this request will return response 301 response.

I am building a script that occasionally goes through all instances of <div data-page="130414917005937" data-app="299770086775725"></div> in my portfolio. Then checks if the app is still on the page. If the app is on the page, it will provide a link, otherwise leave the tag as it was.

I am looking for a solution that does not require access token.

like image 805
Gajus Avatar asked May 14 '12 13:05

Gajus


People also ask

How do I see which Apps are connected to my Facebook page?

Tap in the top right of Facebook. Scroll down and tap Settings. Tap Apps and Websites.


2 Answers

Here's the official way to find out if a Facebook page has the app installed on it.

See http://developers.facebook.com/docs/reference/api/page/

Testing App Installs

You can test if a specific app is installed on a page profile tab by issuing an HTTP GET to PAGE_ID/tabs/APP_ID.

This request will work for any APP_ID and return the above fields is the app is installed on the page. If the app is not installed on the page, this request will return an empty data[] array.

You can also issue this same query with an app access token. In this case, you can query any PAGE_ID, and the above fields will be returned if your app is installed on the specified page. An empty data[] array is returned as usual if the app is not installed on the specified page.

So it's a simple HTTP GET to http://graph.facebook.com/PAGE_ID/tabs/APP_ID

like image 71
DMCS Avatar answered Oct 20 '22 18:10

DMCS


You can examine the http response of the page you are requesting and search for the string pagelet_app_APPID (where APPID is the actual application id)

this addresses issue 1 because this string will not exist on the page if the page requested is not actually the tab application.

in response to issue 2, in the event of a 301, follow the redirect and and search the response of the redirected page for this string.

Edited 10/29/12

I just looked into this issue a little further. The reason that the first page is not available to anonymous users. This is due to some permissions restrictions set by the page admin. It is because of these restrictions that facebook is requiring a user to authenticate before the page is seen. When you use cURL, facebook sees this request as an anonymous user and is redirecting the request to the login page. The second app does not have this issue.

To resolve this, i would suggest inspecting your facebook cookies after you log in using your browser and send those as part of the cURL request.

like image 45
Fisch Avatar answered Oct 20 '22 18:10

Fisch