<jupyter_start><jupyter_text>Facebook API Access<jupyter_code># https://developers.facebook.com/tools/access_token/

ACCESS_TOKEN = '<KEY>'<jupyter_output><empty_output><jupyter_text>Example 1. Making Graph API requests over HTTP<jupyter_code>import requests
import json

base_url = 'https://graph.facebook.com/me'

# Specify which fields to retrieve
fields = 'id,name,likes.limit(10){about}'

url = '{0}?fields={1}&access_token={2}'.format(base_url, fields, ACCESS_TOKEN)

# This API is HTTP-based and could be requested in the browser,
# with a command line utlity like curl, or using just about
# any programming language by making a request to the URL.
# Click the hyperlink that appears in your notebook output
# when you execute this code cell to see for yourself...
print(url)

# Interpret the response as JSON and convert back
# to Python data structures
content = requests.get(url).json()

# Pretty-print the JSON and display it
print(json.dumps(content, indent=1))<jupyter_output>https://graph.facebook.com/me?fields=id,name,likes.limit(10){about}&access_token=<KEY>
{
 "id": "2115365088517697",
 "name": "<NAME>",
 "likes": {
  "data": [
   {
    "about": "MYCS [\u2019miks], der:\n1. das einfache Gestalten individueller M\u00f6bel f\u00fcr Stil- und \nPreisbewusste \n2. auch: das Mycsen",
    "id": "743592712375727"
   },
   {
    "about": "Projekt Neptun is the computing service for students and members of Swiss universities - high quality laptops, tablets and accessories for study & work.",
    "id": "101407263240272"
   },
   {
    "about": "Founded in 2001, Made a Mano is a Danish art and tile company with focus on craft, aesthetics and durability. ",
    "id": "734120903341174"
   },
   {
    "about": "www.mooris.ch ausgew\u00e4hlte Dinge die Freude machen",
    "id": "403149569707876"
  [...]<jupyter_text>Example 2. Querying the Graph API with Python<jupyter_code>import facebook # pip install facebook-sdk
import json

# A helper function to pretty-print Python objects as JSON
def pp(o):
    print(json.dumps(o, indent=1))

# Create a connection to the Graph API with your access token
g = facebook.GraphAPI(ACCESS_TOKEN, version='2.8')

# Execute a few example queries:

# Get my ID
pp(g.get_object('me'))
# Get the connections to an ID
# Example connection names: 'feed', 'likes', 'groups', 'posts'
pp(g.get_connections(id='me', connection_name='likes'))
# Search for a location, may require approved app
pp(g.request("search", {'type': 'place', 'center': '40.749444, -73.968056', 'fields': 'name, location'}))<jupyter_output>{
 "data": [
  {
   "name": "United Nations Headquarter",
   "location": {
    "city": "New York",
    "country": "United States",
    "latitude": 40.750442744222,
    "longitude": -73.967911057302,
    "state": "NY",
    "street": "1st Ave",
    "zip": "10017"
   },
   "id": "538478376162468"
  },
  {
   "name": "<NAME>",
   "location": {
    "city": "New York",
    "country": "United States",
    "latitude": 40.748801288774,
    "longitude": -73.968307971954,
    "state": "NY"
   },
   "id": "10155092544275820"
  },
  {
   "name": "<NAME>",
   "location": {
    "city": "New York",
    "country": "United States",
    "latitude": 40.7142,
    "longitude": -74.0064,
    "state": "NY"
   },
   "id": "207582855939923"
  },
  {
   "name": "<NAME>",
   "location": {
    "city": "New York",
    "country": "United States",
    "latitude": 40.749474401558,
    "longitude": -73.967919463251,
    "state": "NY",
    "street": "760 United Nations Plaza"[...]
{'fraction_non_alphanumeric': 0.15450156205623403, 'fraction_numerical': 0.07810281170122124, 'mean_word_length': 4.060344827586207, 'pattern_counts': {'":': 47, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '498686', 'license': 'MIT', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1235, 'n_words': 346, 'path': 'Facebook.ipynb', 'repo_name': 'GAnagno/Social-Media', 'size': '3894'}