addthis分析api的python包装器

addthis的Python项目详细描述


Latest Versionhttps://travis-ci.org/creafz/python-addthis.svg?branch=masterhttps://coveralls.io/repos/creafz/python-addthis/badge.png?branch=master

用于AddThis Analytics API的python包装器。

要求

安装

从pypi安装:

pip install addthis

用法

from addthis import Addthis

# create an AddThis instance using userid and password from your AddThis account and optionally provide a pubid
addthis = Addthis(userid="YOUR_USER_ID", password="YOUR_PASSWORD", pubid="YOUR_PUB_ID")

# get the number of shares for the last day
print addthis.shares.day()

# get the number of shares by day for the last week
print addthis.shares.day(period="week")

您可以在http://support.addthis.com/customer/portal/articles/381264-addthis-analytics-api

再举几个例子

过去一周,我的内容每天在twitter上共享多少次?

>>> addthis.shares.day(period="week", service="twitter")

pub id=“我的pub\u id”的最大共享url是什么?

>>> addthis.shares.url(pubid="MY_PUB_ID")

这个月有多少用户分享了我的内容,按他们的兴趣分类?

>>> addthis.sharers.interest(period="month")

本周哪些共享服务向我的网站发送了最多的点击?

>>> addthis.clicks.service(period="week")

例外情况

添加此验证错误

addthis对象需要用两个参数来调用-“metric”和“dimension”:

addthis.<metric>.<dimension>()

例如:

>>> addthis.shares.day() # "shares" is a metric and "day" is a dimension

如果它获得其他数量的参数(例如addthis.shares()或addthis.shares.day.week()),它将引发一个addThisValidationError

from addthis import Addthis, AddthisValidationError

addthis = Addthis(userid="YOUR_USER_ID", password="YOUR_PASSWORD", pubid="YOUR_PUB_ID")

try:
    addthis.shares()
except AddthisValidationError as e:
    print e # "Incorrect number of parameters are given. Expected 2 but got 1."

添加此错误

addthisserror在addthis服务返回http状态代码不是200的响应时引发。异常对象有4个属性:

  • 状态代码:来自HTTP响应的代码
  • codemessageattachment:来自AddThis响应体的错误属性(有关详细信息,请参阅AddThis Analytics API documentation中的“错误”部分)
from addthis import Addthis, AddthisError

addthis = Addthis(userid="INCORRECT_USER_ID", password="INCORRECT_PASSWORD", pubid="INCORRECT_PUB_ID")

try:
    addthis.shares.day()
except AddthisError as e:
    print e # "401 Error (code = '80', message='authentication failed', attachment='{u'nonce': None, u'realm': u'AddThis', u'opaque': None})'."
    print e.status_code # 401
    print e.code # 80
    print e.message # "authentication failed"
    print e.attachment # {u'nonce': None, u'realm': u'AddThis', u'opaque': None}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java允许具有不同父类的类扩展类,而无需多重继承   java如何创建动态化的JScrollPane w/JPanel作为客户端?   java如何组织和命名包   在Java中读取属性文件   java无法解释的Android意图行为   在Java中动态执行多个BPEL文件的部署   ssl Java 6 SNI(服务器名称指示)?   java我们可以使用Robot框架自动化web和移动应用程序来执行并行执行   java for star pettern的循环   java为什么BinaryReader在线程中,从netty读取错误的数据包?   在java中将华氏度转换为摄氏度   使用Spark和java处理空值和引号编写CSV文件   Java中已排序日期到块的列表   visual studio代码VSCode Java不是linting或自动完成局部变量,而是自动完成Java快捷方式,如“sysout”