python Facebook即时文章API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Facebook即时文章API相关的知识,希望对你有一定的参考价值。
FB_INSTANT_TOKEN = 'The token'
FB_PAGE_ID = 'The fb page id'
class FBInstantArticle:
def __init__(self, slug, published=False, development_mode=False):
self.page_token = FB_INSTANT_TOKEN
self.page_id = FB_PAGE_ID
self.host = 'https://graph.facebook.com/'
klass = import_class('article.models.Article')
self.article = get_obj(klass, slug=slug)
self.published = published
self.development_mode = development_mode
def post(self):
try:
if self.article:
article = self.article
url = self.host + self.page_id + '/instant_articles'
template = render_to_string('articles/fb_instant_article.html', {'article': article })
params = {
'access_token': self.page_token,
'html_source': template,
'published': self.published,
'development_mode': self.development_mode
}
response = requests.post(url, timeout=5, params=params)
# Update fia to True
if response.status_code == 200:
res = response.json()
inst_art_id = res.get('id', None)
if not inst_art_id:
raise Exception('Not found any instant article id ')
article.fb_ins_art_id = inst_art_id
article.save()
return response
except Exception as e:
logger.error(e)
以上是关于python Facebook即时文章API的主要内容,如果未能解决你的问题,请参考以下文章
Python即时网络爬虫:API说明
python实现快递鸟即时查询API接口 数据签名验证
Facebook 等即时通知
Facebook 即时验证未通过 Facebook 应用验证手机号码
Python Facebook API - 光标分页
在 AWS Cognito 和 Lambda 中获取 Facebook 访问令牌