Python: Get the number of followers of Facebook users

Source: Internet
Author: User

Python: Get the number of followers of Facebook users

CODE:

#!/usr/bin/python # -*- coding: utf-8 -*-'''Created on 2014-8-9@author: guaguastd@name: fan_pages_compare.py'''# impot loginfrom login import facebook_login# import helperfrom helper import pp, int_format# access to facebookfacebook_api = facebook_login()# find Pepsi and Coke in search resultsprint '---------------'print 'Query for Pepsi by name'print '---------------'name = 'pepsi'pp(facebook_api.request('search', {'q': name, 'type': 'page', 'limit':5}))printprint '---------------'print 'Query for Coke by name'print '---------------'name = 'coke'pp(facebook_api.request('search', {'q': name, 'type': 'page', 'limit':5}))print# Use the ids to query for likespepsi_id = '56381779049' # Could also uee 'PepsiUS'coke_id = '40796308305'  # Could also use 'CocaCola'print '---------------'print 'Query for likes'print '---------------'print "Pepsi likes:", int_format(facebook_api.get_object(pepsi_id)['likes'])print "Coke likes:", int_format(facebook_api.get_object(coke_id)['likes'])

RESULT:

---------------Query for Pepsi by name---------------{ "paging": {  "next": "https://graph.facebook.com/v1.0/search?limit=5&type=page&q=pepsi&access_token=...&offset=5&__after_id=enc_AeyEr2DOhYDDNGDRR0gUWr8xWN00Uq4BFCKMhCFNVtQU1hEBy8S1gbL7inKsbRqbIvo" },  "data": [  {   "category": "Food/beverages",    "name": "Pepsi",    "id": "339150749455906"  },   {   "category": "Food/beverages",    "name": "Pepsithai",    "id": "63619711274"  },   {   "category": "Food/beverages",    "name": "PepsiCo",    "category_list": [    {     "id": "2252",      "name": "Food/Beverages"    }   ],    "id": "260431051694"  },   {   "category": "Company",    "name": "Pepsi Center",    "category_list": [    {     "id": "211155112228091",      "name": "Event Venue"    },     {     "id": "109976259083543",      "name": "Sports Venue & Stadium"    }   ],    "id": "111829892187838"  },   {   "category": "Arts/entertainment/nightlife",    "name": "Pepsi Club",    "category_list": [    {     "id": "191478144212980",      "name": "Night Club"    }   ],    "id": "194989311723"  } ]}---------------Query for Coke by name---------------{ "paging": {  "next": "https://graph.facebook.com/v1.0/search?limit=5&type=page&q=coke&access_token=...&offset=5&__after_id=enc_AexTzaGHp5s3B1YHpjyu7izJPFN5xkZs5QC5d1kuDa1auOC5Sv7PD3Dk5dUTZNO0qzY" },  "data": [  {   "category": "Food/beverages",    "name": "Coca-Cola",    "id": "40796308305"  },   {   "category": "Tv show",    "name": "Coke Studio",    "category_list": [    {     "id": "133436743388217",      "name": "Arts & Entertainment"    }   ],    "id": "16944632531"  },   {   "category": "Tv show",    "name": "Coke Studio at MTV",    "id": "127266094017030"  },   {   "category": "Food/beverages",    "name": "Coca-Cola Zero",    "id": "61124008229"  },   {   "category": "Food/beverages",    "name": "Diet Coke",    "id": "8605796091"  } ]}---------------Query for likes---------------Pepsi likes: 33,027,024Coke likes: 87,244,352


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.