Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Facebook Public Page Content Access just to extract data?

For a project at university I need to extract data such as posts and reviews from same Facebook pages. Everything was fine couple of months ago but now to get data from pages you need the Public Page Content Access.

In order to get my app reviewed I need to add:

  • A platform where I'd use the app
  • A screencast that shows "how a person sees this feature used in your app"
  • An explanation of how I'd be using Page Public Content Access to enhance the experience of my app.
  • Privacy Policy URL

As a student who just needs to extract some data for an exam I don't have any website/platform where I'd use the app. I'm using the Facebook Graph API on Python.
I looked on this website for a Privacy Policy Generator but I don't have any website nor mobile apps where I'd use the API...

Is there some way for my situation to extract data by API without this requirements or it's better for me to find other solutions, such as web scraping?

like image 374
silviacamplani Avatar asked Jul 07 '18 09:07

silviacamplani


People also ask

What is page public content access?

The Page Public Content Access feature allows your app access to the Pages Search API and to read public data for Pages for which you lack the pages_read_engagement permission and the pages_read_user_content permission. Readable data includes business metadata, public comments and posts.

What is Facebook public data?

Facebook Public Data connector will allow visualizing competitors' performance to integrate relevant information to your category reporting straight to Google Data Studio dashboards.

Is the Facebook API free?

In the newest version of the Graph API (v2. 9), we're announcing features that simplify development, making it even easier to build apps and experiences with Facebook. We're providing free access to over 140 million places around the world, the same data that powers Facebook, Instagram, and Messenger.

How do I request access to a Facebook page?

Once logged into your Facebook Business Manager account follow these steps: Go to settings. Select Pages in the left navigation. Click the Add New Page button near the top right of the screen. Select Request access to a Page.

How to export Facebook pages data?

To export your Facebook Pages data for the pages you’re an admin of, you can follow the standard process: Click the “ Deselect All ” button. Select “ Pages ” from the categories. Proceed with the next steps and create your file. Another useful type of data you can export is your Facebook friends data.

What is the Facebook page public content access permission?

The latest answer I got is: "the Page Public Content Access permission is for comparing results from different pages. An example could be comparing likes of different restaurants across different Facebook pages. In your screencast, you scroll through posts and this is now a valid use case for the Page Public Content Access Permission.

How to extract data from Facebook using Python code?

To be able to extract data from Facebook using a python code you need to register as a developer on Facebook and then have an access token. Here are the steps for it. Go to link developers.facebook.com, create an account there.


1 Answers

To be able to extract data from Facebook using a python code you need to register as a developer on Facebook and then have an access token. Here are the steps for it.

Go to link developers.facebook.com, create an account there. Go to link developers.facebook.com/tools/explorer. Go to “My apps” drop down in the top right corner and select “add a new app”. Choose a display name and a category and then “Create App ID”. Again get back to the same link developers.facebook.com/tools/explorer. You will see “Graph API Explorer” below “My Apps” in the top right corner. From “Graph API Explorer” drop down, select your app. Then, select “Get Token”. From this drop down, select “Get User Access Token”. Select permissions from the menu that appears and then select “Get Access Token.” Go to link developers.facebook.com/tools/accesstoken. Select “Debug” corresponding to “User Token”. Go to “Extend Token Access”. This will ensure that your token does not expire every two hours.

Python Code to Access Facebook Public Data: Go to link https://developers.facebook.com/docs/graph-api if want to collect data on anything that is available publicly. See https://developers.facebook.com/docs/graph-api/reference/v2.7/. From this documentation, choose any field you want from which you want to extract data such as “groups” or “pages” etc. Go to examples of codes after having selected these and then select “facebook graph api” and you will get hints on how to extract information. This blog is primarily on getting events data. First of all, import ‘urllib3’, ‘facebook’, ‘requests’ if they are already available. If not, download these libraries. Define a variable token and set its value to what you got above as “User Access Token”.

token= ‘aiufniqaefncqiuhfencioaeusKJBNfljabicnlkjshniuwnscslkjjndfi’

Getting list of Events: Now to find information on events for any search term say “Poetry” and limiting those events’ number to 10000:

graph = facebook.GraphAPI(access_token=token, version = 2.7)
events = graph.request(‘/search?q=Poetry&type=event&limit=10000’)

This will give a dictionary of all the events that have been created on Facebook and has string “Poetry” in its name. To get the list of events, do:

eventList = events[‘data’]

Extracting all information for a event from the list of events extracted above: Get the EventID of the first event in the list by

eventid = eventList[1][‘id’]

For this EventID, get all information and set few variables which will be used later by:

event1=graph.get_object(id=eventid,fields=’attending_count,can_guests_invite,category,cover,declined_count,description,end_time,guest_list_enabled,interested_count,is_canceled,is_page_owned,is_viewer_admin,maybe_count,noreply_count,owner,parent_group,place,ticket_uri,timezone,type,updated_time’)
attenderscount = event1[‘attending_count’]
declinerscount = event1[‘declined_count’]
interestedcount = event1[‘interested_count’]
maybecount = event1[‘maybe_count’]
noreplycount = event1[‘noreply_count’]

Getting the list of all those who are attending an event and converting the response into json format:

attenders = requests.get(“https://graph.facebook.com/v2.7/"+eventid+"/attending? 
access_token="+token+”&limit=”+str(attenderscount)) 
attenders_json = attenders.json()

Getting the admins of the event:

admins = requests.get(“https://graph.facebook.com/v2.7/"+eventid+"/admins? 
access_token="+token)
admins_json = admins.json()

And similarly you can extract other information such as photos/videos/feed of that event if you want. Go to https://developers.facebook.com/docs/graph-api/reference/event/ and see “Edges” part in the documentation.

like image 192
huzefausama Avatar answered Oct 23 '22 22:10

huzefausama