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_api = facebook_login()

# find Pepsi and Coke in search results
print '---------------'
print 'Query for Pepsi by name'
print '---------------'
name = 'pepsi'
pp(facebook_api.request('search', {'q': name, 'type': 'page', 'limit':5}))
print

print '---------------'
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 likes
pepsi_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,024
Coke likes: 87,244,352


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值