Python accessing Facebook (http)
CODE:
#!/usr/bin/python # -*- coding: utf-8 -*-'''Created on 2014-8-6@author: guaguastd@name: http.py'''# Request over httpdef 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 jsonfrom http import request_over_httpurl = 'https://graph.facebook.com/me'access_token = ''# Get 10 likes for 10 friendsfields = '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"}