本文整理汇总了Python中weibo.APIClient.short_url__shorten方法的典型用法代码示例。如果您正苦于以下问题:Python APIClient.short_url__shorten方法的具体用法?Python APIClient.short_url__shorten怎么用?Python APIClient.short_url__shorten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weibo.APIClient
的用法示例。
在下文中一共展示了APIClient.short_url__shorten方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _post_poem
# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import short_url__shorten [as 别名]
def _post_poem(poem):
' post poem to weibo using official account '
users = list(web.ctx.db.select('user', where='id=$id', vars=dict(id=_SHI_CI_ID)))
if not users:
raise StandardError('official user not found.')
user = users[0]
client = APIClient(_APP_KEY, _APP_SECRET, _CALLBACK)
client.set_access_token(user.oauth_access_token, user.oauth_expires)
url_long = 'http://www.shi-ci.com/poem/%s' % poem.id
urls = client.short_url__shorten(url_long=url_long)
logging.info('short_url/shorten result: %s' % str(urls))
url_short = urls['urls'][0]['url_short']
head = u'%s(%s):' % (poem.name, poem.poet_name)
if poem.poet_name==u'毛泽东':
head = u'%s:' % poem.name
body_left = (280 - 2 - len(url_short) - 2 * len(head)) // 2
if len(poem.content) <= body_left:
text = u'%s%s %s' % (head, poem.content, url_short)
else:
text = u'%s%s... %s' % (head, poem.content[:body_left-2], url_short)
r = client.post.statuses__update(status=text)
logging.info('statuses/update result: %s' % str(r))
return r['id']