Python 访问Facebook (http)

CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Created on 2014-8-6
@author: guaguastd
@name: http.py
'''

# Request over http
def request_over_http(access_token, url, fields):

    # import requests
    import requests

    # Build the urls
    urls = '%s?fields=%s&access_token=%s' % (url, fields, access_token)
    print 'urls: ', urls

    # Get the content
    content = requests.get(urls, verify=False).json()

    # return
    return content
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Created on 2014-8-7
@author: guaguastd
@name: graph_api_request.py
'''

import json

from http import request_over_http

url = 'https://graph.facebook.com/me'
access_token = ''

# Get 10 likes for 10 friends
fields = 'id,name,friends.limit(10).fields(likes.limit(10))'
content = request_over_http(access_token, url, fields)
print json.dumps(content, indent=1)

RESULT:

{
 "friends": {
  "paging": {
   "next": "https://graph.facebook.com/v1.0/100006272283550/friends?limit=10&fields=likes.limit%2810%29&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&offset=10&__after_id=enc_Aeyi-ryRJ8KKYuH3F9k8nuPblpv9iCVVmzo8up78NxwEE25Q0XtdwqbYMRtPJszzrEZCE1Db2rVMCXL229StbZuh"
  },
  "data": [
   {
    "id": "1568560418",
    "likes": {
     "paging": {
      "cursors": {
       "after": "MjgyNTg1Njk4NTA4MzQ1",
       "before": "NjM2MjA0Mjk5Nzg4NjEw"
      },
      "next": "https://graph.facebook.com/v1.0/1568560418/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=MjgyNTg1Njk4NTA4MzQ1"
     },
     "data": [
      {
       "category": "Community organization",
       "created_time": "2014-05-28T03:12:01+0000",
       "name": "Mil maneras de decirle sutilmente a alguien que no te gusta",
       "id": "636204299788610"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-05-02T00:22:56+0000",
       "name": "BOCA",
       "category_list": [
        {
         "id": "1801",
         "name": "Professional Sports Team"
        }
       ],
       "id": "114264528738492"
      },
      {
       "category": "Community",
       "created_time": "2014-02-13T01:21:46+0000",
       "name": "Hip\u00f3dromo de Lincoln fotograf\u00edas",
       "id": "195376183994226"
      },
      {
       "category": "Product/service",
       "created_time": "2013-04-28T19:34:45+0000",
       "name": "Samsung Mobile",
       "id": "114219621960016"
      },
      {
       "category": "Product/service",
       "created_time": "2013-03-16T15:24:29+0000",
       "name": "Mozilla Firefox",
       "id": "14696440021"
      },
      {
       "category": "Food/beverages",
       "created_time": "2013-03-14T00:08:13+0000",
       "name": "Cerveza Brahma",
       "id": "69004099657"
      },
      {
       "category": "Entertainment website",
       "created_time": "2013-03-04T02:27:37+0000",
       "name": "Ca\u00fa Ca\u00fa - MiXto",
       "id": "276098382433624"
      },
      {
       "category": "Society/culture website",
       "created_time": "2013-02-21T02:00:28+0000",
       "name": "Aun Sigooo Pensando En TI",
       "id": "101431640015012"
      },
      {
       "category": "Community",
       "created_time": "2013-01-17T00:10:34+0000",
       "name": "Nada es lo mismo sin Futbol",
       "id": "518822228157833"
      },
      {
       "category": "Website",
       "created_time": "2012-12-05T09:53:21+0000",
       "name": "Destander Internacional",
       "id": "282585698508345"
      }
     ]
    }
   },
   {
    "id": "100002532817761",
    "likes": {
     "paging": {
      "cursors": {
       "after": "NTEyOTY4Nzg4NzM2Mzc3",
       "before": "NDc5NjA3MzAyMTAxOTc3"
      },
      "next": "https://graph.facebook.com/v1.0/100002532817761/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=NTEyOTY4Nzg4NzM2Mzc3"
     },
     "data": [
      {
       "category": "Games/toys",
       "created_time": "2014-06-14T19:19:29+0000",
       "name": "Hra Pou",
       "id": "479607302101977"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-05-24T23:44:54+0000",
       "name": "El Linque\u00f1o",
       "id": "109679792391529"
      },
      {
       "category": "Website",
       "created_time": "2014-05-06T01:13:54+0000",
       "name": "Aprender a ser feliz",
       "id": "260719930611785"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-03-18T23:37:44+0000",
       "name": "Bernardita",
       "id": "1480890645464677"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-03-07T21:32:31+0000",
       "name": "Facu ledesma",
       "id": "414627398579431"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-03-07T16:54:08+0000",
       "name": "The Vis",
       "id": "754043891277599"
      },
      {
       "category": "City",
       "created_time": "2014-02-27T13:19:57+0000",
       "name": "Jun\u00edn, Buenos Aires",
       "category_list": [
        {
         "id": "224455390913969",
         "name": "City"
        }
       ],
       "id": "108378849192690"
      },
      {
       "category": "Community",
       "created_time": "2014-02-22T01:48:48+0000",
       "name": "Egoo lincoln",
       "category_list": [
        {
         "id": "110290705711626",
         "name": "Bar"
        }
       ],
       "id": "615927198434627"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-02-20T18:26:00+0000",
       "name": "Porta",
       "id": "13909772021"
      },
      {
       "category": "Just for fun",
       "created_time": "2014-02-18T21:35:44+0000",
       "name": "Crea Carteles",
       "id": "512968788736377"
      }
     ]
    }
   },
   {
    "id": "100004245243800",
    "likes": {
     "paging": {
      "cursors": {
       "after": "MjIzNjc0NzExMDUwNjMz",
       "before": "MjkxMTkyMDA3NTU4MjE1"
      },
      "next": "https://graph.facebook.com/v1.0/100004245243800/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=MjIzNjc0NzExMDUwNjMz"
     },
     "data": [
      {
       "category": "Musician/band",
       "created_time": "2014-07-26T17:45:39+0000",
       "name": "Casi Justicia Social",
       "id": "291192007558215"
      },
      {
       "category": "Athlete",
       "created_time": "2014-07-15T03:30:07+0000",
       "name": "Leo Messi",
       "id": "176063032413299"
      },
      {
       "category": "Concert tour",
       "created_time": "2014-06-19T14:53:14+0000",
       "name": "Rocanrol del Pa\u00eds",
       "category_list": [
        {
         "id": "189811544396762",
         "name": "Tour Company"
        },
        {
         "id": "189483194405517",
         "name": "Music Production"
        }
       ],
       "id": "120829411335868"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-04-25T05:57:38+0000",
       "name": "Casi Justicia Social",
       "id": "186801098006391"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-04-13T00:34:42+0000",
       "name": "Patricio Santos Fontanet",
       "id": "129227477145991"
      },
      {
       "category": "Clothing",
       "created_time": "2014-04-11T00:59:20+0000",
       "name": "Pink Sowa",
       "id": "315625671848264"
      },
      {
       "category": "Community",
       "created_time": "2014-04-11T00:58:41+0000",
       "name": "Carla Alzarise Make Up",
       "id": "635673476494422"
      },
      {
       "category": "Artist",
       "created_time": "2014-04-11T00:58:14+0000",
       "name": "Pau Scarso Photography",
       "id": "311476752304841"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-04-02T14:49:23+0000",
       "name": "Callejeros",
       "id": "112518935427743"
      },
      {
       "category": "Community",
       "created_time": "2014-01-10T04:41:06+0000",
       "name": "Desmotivaciones",
       "id": "223674711050633"
      }
     ]
    }
   },
   {
    "id": "100005898397613",
    "likes": {
     "paging": {
      "cursors": {
       "after": "NzI5NTU4NTQwMzk1NzAy",
       "before": "NDczMDU1MzUyNzYwNzQw"
      },
      "next": "https://graph.facebook.com/v1.0/100005898397613/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=NzI5NTU4NTQwMzk1NzAy"
     },
     "data": [
      {
       "category": "Artist",
       "created_time": "2014-07-21T21:28:06+0000",
       "name": "Mariia",
       "id": "473055352760740"
      },
      {
       "category": "Public figure",
       "created_time": "2014-03-26T01:34:49+0000",
       "name": "Yo querer Comidaaaaaaaa",
       "id": "1485476044997944"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-03-04T06:08:39+0000",
       "name": "Justin Bieber",
       "category_list": [
        {
         "id": "180164648685982",
         "name": "Bands & Musicians"
        }
       ],
       "id": "67253243887"
      },
      {
       "category": "Dancer",
       "created_time": "2014-03-04T05:59:27+0000",
       "name": "Odio a violetta",
       "id": "477044532392301"
      },
      {
       "category": "Just for fun",
       "created_time": "2014-03-04T00:17:31+0000",
       "name": "Hay Si Voy A Llorar Por Que No Me Hablas",
       "id": "200571013335090"
      },
      {
       "category": "Artist",
       "created_time": "2014-03-01T19:12:16+0000",
       "name": "ElrusOMG",
       "id": "243428735824540"
      },
      {
       "category": "Community",
       "created_time": "2014-03-01T19:07:05+0000",
       "name": "Mundo De Chicas",
       "id": "712814788750011"
      },
      {
       "category": "Book",
       "created_time": "2014-03-01T19:05:01+0000",
       "name": "Alone With Vampire",
       "id": "1428572367384217"
      },
      {
       "category": "Public figure",
       "created_time": "2014-03-01T19:05:01+0000",
       "name": "\u0627\u0635\u0639\u0628 \u0637\u0631\u064a\u0642",
       "id": "394277387335472"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-03-01T19:04:57+0000",
       "name": "Katerine Acosta Y Candela Ojeda",
       "id": "729558540395702"
      }
     ]
    }
   },
   {
    "id": "100006621541500",
    "likes": {
     "paging": {
      "cursors": {
       "after": "NTQ1ODY1MDI1NDQ0Mjc1",
       "before": "Mjc1NDA0MDc5MjAwNzQz"
      },
      "next": "https://graph.facebook.com/v1.0/100006621541500/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=NTQ1ODY1MDI1NDQ0Mjc1"
     },
     "data": [
      {
       "category": "Artist",
       "created_time": "2014-08-01T06:39:22+0000",
       "name": "\u00d1engo Flow",
       "id": "275404079200743"
      },
      {
       "category": "Community",
       "created_time": "2014-07-29T08:22:03+0000",
       "name": "Bebes con swag",
       "id": "151647501700035"
      },
      {
       "category": "Fictional character",
       "created_time": "2014-07-29T08:15:40+0000",
       "name": "AMI TAMBIEN ME CONFUNDEN LOS MELLISOS",
       "id": "157790577615959"
      },
      {
       "category": "Book",
       "created_time": "2014-07-29T08:14:04+0000",
       "name": "los bebes mas lindos",
       "id": "253170598035126"
      },
      {
       "category": "Album",
       "created_time": "2014-07-29T08:09:37+0000",
       "name": "Los bebes mas hermosos",
       "id": "433409126748083"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-29T08:00:33+0000",
       "name": "Niall horan i'm in love with you",
       "id": "128806290603262"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-29T08:00:32+0000",
       "name": "Liam Payne",
       "id": "352476444849191"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-29T08:00:30+0000",
       "name": "Niall Horan.",
       "id": "351529728293010"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-29T08:00:28+0000",
       "name": "1D Are My Super Humans",
       "id": "220658024722975"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-29T08:00:26+0000",
       "name": "Tributo a One Direction - Per\u00fa",
       "id": "545865025444275"
      }
     ]
    }
   },
   {
    "id": "100006854221707",
    "likes": {
     "paging": {
      "cursors": {
       "after": "Mzc0MDQ5NTg2MDUwOTA0",
       "before": "MjE3NTMxMDY0OTMzMDM5"
      },
      "next": "https://graph.facebook.com/v1.0/100006854221707/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=Mzc0MDQ5NTg2MDUwOTA0"
     },
     "data": [
      {
       "category": "Community",
       "created_time": "2014-07-31T02:49:30+0000",
       "name": "Desparramados de Nueva Chicago",
       "id": "217531064933039"
      },
      {
       "category": "Community",
       "created_time": "2014-07-31T02:49:14+0000",
       "name": "CEF 69",
       "id": "143952422291988"
      },
      {
       "category": "Community",
       "created_time": "2014-07-31T02:49:04+0000",
       "name": "Lluvias, besos, silencios, lunas y esas miradas que tanto extra\u00f1o",
       "id": "253048448145765"
      },
      {
       "category": "Community",
       "created_time": "2014-07-31T02:48:59+0000",
       "name": "Tu & yo pareja perfecta",
       "id": "503778376303648"
      },
      {
       "category": "Entertainer",
       "created_time": "2014-07-31T02:48:57+0000",
       "name": "Te invito a ser feliz, yo pago",
       "id": "408359209198171"
      },
      {
       "category": "Actor/director",
       "created_time": "2014-07-13T15:33:38+0000",
       "name": "Av.Brasil",
       "id": "191707154353786"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-07-13T15:33:32+0000",
       "name": "Brasil decime que se siente.",
       "id": "1513572578862384"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-07-13T15:33:30+0000",
       "name": "Hincha de Nueva Chicago desde la cuna hasta el infinito",
       "id": "300423600055252"
      },
      {
       "category": "Community",
       "created_time": "2014-07-10T14:21:59+0000",
       "name": "Te Amo Y Que Alg\u00fan Problema",
       "id": "653444204702887"
      },
      {
       "category": "Community",
       "created_time": "2014-07-05T21:41:29+0000",
       "name": "\u30c4Eres Adicto Al Pou,Admitelo\u30c4",
       "id": "374049586050904"
      }
     ]
    }
   },
   {
    "id": "100006992200890",
    "likes": {
     "paging": {
      "cursors": {
       "after": "MTIzOTU2NDkwOTQ5ODI5",
       "before": "MTIzOTU2NDkwOTQ5ODI5"
      }
     },
     "data": [
      {
       "category": "School",
       "created_time": "2013-11-08T07:07:45+0000",
       "name": "\u6538\u53bf\u4e00\u4e2d",
       "id": "123956490949829"
      }
     ]
    }
   },
   {
    "id": "100007488665589",
    "likes": {
     "paging": {
      "cursors": {
       "after": "MjEwMjg1NzQ5MDg5NzIx",
       "before": "MTA4MTc5MjI1ODczODcw"
      }
     },
     "data": [
      {
       "category": "Professional sports team",
       "created_time": "2014-06-22T17:21:02+0000",
       "name": "Boca Juniors",
       "id": "108179225873870"
      },
      {
       "category": "Website",
       "created_time": "2014-06-19T19:52:16+0000",
       "name": "Mis Carteles",
       "id": "478799118806621"
      },
      {
       "category": "Sports league",
       "created_time": "2014-06-02T19:41:31+0000",
       "name": "Pasion Xeneize",
       "id": "602688296504767"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-05-06T03:05:33+0000",
       "name": "Prince Royce",
       "id": "116842969002"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-05-06T03:05:31+0000",
       "name": "Romeo Santos",
       "id": "117414898335812"
      },
      {
       "category": "Public figure",
       "created_time": "2014-02-13T19:15:06+0000",
       "name": "Cristian Gomez",
       "id": "565275260213609"
      },
      {
       "category": "Food/beverages",
       "created_time": "2014-01-25T01:36:34+0000",
       "name": "Tang Argentina",
       "id": "210285749089721"
      }
     ]
    }
   },
   {
    "id": "100007752073848",
    "likes": {
     "paging": {
      "cursors": {
       "after": "Mjk4MTc1NzEwMzU4MzEz",
       "before": "MTA3OTIzMzYyNTYxMjUy"
      },
      "next": "https://graph.facebook.com/v1.0/100007752073848/likes?limit=10&access_token=CAACEdEose0cpCIdzroQUzDoFprh9KgTx1tytqbloqc7Ca31WNdubO8MdFJjzLB9ZCID3J07NoUxX8VyEZD&after=Mjk4MTc1NzEwMzU4MzEz"
     },
     "data": [
      {
       "category": "Athlete",
       "created_time": "2014-06-05T00:42:01+0000",
       "name": "Carlos Tevez",
       "id": "107923362561252"
      },
      {
       "category": "Athlete",
       "created_time": "2014-06-05T00:41:58+0000",
       "name": "Juan Roman Riquelme Web",
       "id": "65239713915"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-06-05T00:41:51+0000",
       "name": "Skrillex",
       "id": "119702488081975"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-06-05T00:41:40+0000",
       "name": "Miley Cyrus",
       "id": "5845317146"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-06-05T00:41:26+0000",
       "name": "BOCA",
       "category_list": [
        {
         "id": "1801",
         "name": "Professional Sports Team"
        }
       ],
       "id": "114264528738492"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-06-05T00:41:25+0000",
       "name": "SoyBoca",
       "id": "128436247184676"
      },
      {
       "category": "Professional sports team",
       "created_time": "2014-06-05T00:41:24+0000",
       "name": "Boca Juniors",
       "id": "108179225873870"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-05-29T04:32:05+0000",
       "name": "Usher",
       "id": "6564142497"
      },
      {
       "category": "Musician/band",
       "created_time": "2014-05-29T03:59:40+0000",
       "name": "Justin Bieber",
       "category_list": [
        {
         "id": "180164648685982",
         "name": "Bands & Musicians"
        }
       ],
       "id": "67253243887"
      },
      {
       "category": "Community",
       "created_time": "2014-05-27T15:11:12+0000",
       "name": "Kevin Camacho",
       "id": "298175710358313"
      }
     ]
    }
   }
  ]
 },
 "id": "100006272283550",
 "name": "Beyond Zhou"
}

Python 访问Facebook (http)

时间: 2024-10-21 12:51:29

Python 访问Facebook (http)的相关文章

fedora python访问mysql

1 下载驱动库 http://sourceforge.net/projects/mysql-python/ 2, yum install mysql-dev* yum install python-dev* 3, python setup.py install fedora python访问mysql,布布扣,bubuko.com

Debian下无root权限使用Python访问Oracle

这篇文章的起因是,在公司的服务器上没有root权限,但是需要使用 Python 访问 Oracle,而不管是使用 pip 安装组件还是安装 Oracle 的 client,都需要相应权限.本文即解决该问题. 使用 virtualenv 使用系统自带 Python 和 pip 安装组件时,默认会安装到系统目录下,需要 root 权限才能执行写操作. 不管是从资源隔离的角度,还是从绕过 root 的角度,你都需要一套顺手的 Python 虚拟环境工具:virtualenv. 去求运维哥哥帮忙安装 v

python 访问限制

在Class内部,可以有属性和方法,而外部代码可以通过直接调用实例变量的方法来操作数据,这样,就隐藏了内部的复杂逻辑. 但是,从前面Student类的定义来看,外部代码还是可以自由地修改一个实例的name.score属性: >>> bart = Student('Bart Simpson', 98) >>> bart.score 98 >>> bart.score = 59 >>> bart.score 59 如果要让内部属性不被外部

Python 访问 LinkedIn (API)

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-16 @author: guaguastd @name: login.py ''' # twitter login def linkedin_login(): from linkedin import linkedin CONSUMER_KEY = '' CONSUMER_SECRET = '' USER_TOKEN = '' USER_SECRET = '

Python访问PostGIS(建表、空间索引、分区表)

#encoding: utf-8 __author__ = 'Administrator' import psycopg2 import ppygis import datetime import string import sys import logging import GeowayLogger reload(sys) #中文错误 sys.setdefaultencoding( "utf-8" ) vLog = GeowayLogger.GeowayLogger("c:

Python访问MySQL数据库

#encoding: utf-8 import mysql.connector __author__ = 'Administrator' config={'host':'127.0.0.1',#默认127.0.0.1 'user':'root', 'password':'root', 'port':3306 ,#默认即为3306 'database':'test', 'charset':'utf8'#默认即为utf8 } if __name__=="__main__": print(c

Python访问MongoDB数据库

#encoding: utf-8 __author__ = 'Administrator' #import pymongo from pymongo import MongoClient,GEO2D import sqlite3 import sys import psycopg2 import ppygis import cx_Oracle import datetime reload(sys) #中文错误 sys.setdefaultencoding( "utf-8" ) #mon

使用python访问网络上的数据

这两天看完了Course上面的: 使用 Python 访问网络数据 https://www.coursera.org/learn/python-network-data/ 写了一些作业,完成了一些作业.做些学习笔记以做备忘. 1.正则表达式 --- 虽然后面的课程没有怎么用到这个知识点,但是这个技能还是蛮好的. 附上课程中列出来的主要正则表达式的用法: Python Regular Expression Quick Guide ^ Matches the beginning of a line

Python 获取Facebook特定用户的粉丝数

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-9 @author: guaguastd @name: fan_pages_compare.py ''' # impot login from login import facebook_login # import helper from helper import pp, int_format # access to facebook facebook_