未加星标

Catalin George Festila: The flickrapi python module .

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Flickr is one of the most popular photo hosting websites.

The development team let us to test the API and with a plenty of opportunity to use Flickr .

Today I tested the flickrapi python module.

I used the python 2.7 version and pip to install it.

C:\>cd Python27 C:\Python27>cd Scripts C:\Python27\Scripts>pip install flickrapi Collecting flickrapi Downloading flickrapi-2.3-py2-none-any.whl ... Running setup.py install for oauthlib ... done Successfully installed flickrapi-2.3 oauthlib-2.0.2 requests-oauthlib-0.8.0 requests-toolbelt-0.8.0

You need to have / make a API key into Account Settings , see my api key:

Your API keys You have 1 API key registered to this account.

Then you need to know your user_id .

This can be done by asking api online with your user name and the result will be something like this: [email protected] .

The example I used is from documentation and I change with my api key to test this python module.

>>>import flickrapi >>> >>>api_key = u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' >>>api_secret = u'YYYYYYYYYYYYYYYYYYYYYYY' >>> >>>flickr = flickrapi.FlickrAPI(api_key, api_secret) >>>photos = flickr.photos.search(user_id='[email protected]', per_page='10') >>>sets = flickr.photosets.getList(user_id='[email protected]') >>> dir(sets) ['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '_init', 'addnext', 'addprevious', 'append', 'attrib', 'base', 'clear', 'cssselect', 'extend', 'find', 'findall', 'findtext', 'get', 'getchildren', 'getiterator', 'getnext', 'getparent', 'getprevious', 'getroottree', 'index', 'insert', 'items', 'iter', 'iterancestors', 'iterchildren', 'iterdescendants', 'iterfind', 'itersiblings', 'itertext', 'keys', 'makeelement', 'nsmap', 'prefix', 'remove', 'replace', 'set', 'sourceline', 'tag', 'tail', 'text', 'values', 'xpath'] >>> print sets.attrib['stat'] ok >>> sets.find('photosets').attrib {'total': '4', 'perpage': '4', 'page': '1', 'pages': '1'} >>> print "upload a photo via browser - set permisions" upload a photo via browser - set permisions >>> flickr.authenticate_via_browser(perms='write') 127.0.0.1 - - [12/Aug/2017 22:05:00] "GET /?oauth_token=xxxxxx-xxxxx&oauth_verifier=xxxxxxxxx HTTP/1.1" 200 - >>> flickr.upload("0001.gif") >>> print "try show title of my photos and id" try show title of my photos and id for child in photos: for i in child: photo_set = [] try: title = i.attrib['title'] print title except Exception, e: print e sets = flickr.photos_getAllContexts(photo_id = i.attrib["id"]) for j in sets: if j.tag == "set": photo_set.append(j.attrib["id"]) print photo_set

The result is my photos title and id:

painting_world

DSC_0112

['72157632077721715']

DSC_0111

['72157632077721715']

DSC_0113

['72157632077721715']

DSC_0110

['72157632077721715']

DSC_0094

['72157632077721715']

DSC_0091

['72157632077721715']

DSC_0108

I tested wit Python 362 version:

C:\Python27>cd .. C:\>cd Python362 C:\Python362>cd Scripts C:\Python362\Scripts>pip install flickrapi Collecting flickrapi Downloading flickrapi-2.3-py3-none-any.whl Collecting requests>=2.2.1 (from flickrapi) Downloading requests-2.18.3-py2.py3-none-any.whl (88kB) 100% |%

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: Python
分页:12
转载请注明
本文标题:Catalin George Festila: The flickrapi python module .
本站链接:http://www.codesec.net/view/561312.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(37)