【问题标题】:flickrAPI upload photosflickrAPI 上传照片
【发布时间】:2021-06-14 13:12:48
【问题描述】:

我正在尝试使用 python Flickr API 将照片上传到我的 Flickr 帐户。我已经获得了 API 密钥和秘密,并使用它们来获取有关我的相册和照片的信息,但是在尝试上传新照片时遇到了一些错误。这是我的代码:

import flickrapi
api_key = u'xxxxxxxxxxxxxxxxxxxxxxxx'
api_secret = u'xxxxxxxxxxxxxxxxxxxx'
flickr = flickrapi.FlickrAPI(api_key, api_secret)
filename = 'd:/downloads/_D4_6263-Enhanced.png'
title = 'Fach Halcones'
description = 'Posting image using API'
tags = 'fidae'+','+'aviation'+','+'extra'+','+'air shows'
flickr.upload(filename, title, description, tags)

当我运行脚本时,出现以下错误:

File "uploadPhotos.py", line 15, in module
flickr.upload(filename, title, description, tags)
TypeError: upload() takes from 2 to 4 positional arguments but 5 were given

查看 Flickr API 文档,它似乎最多可以接受五个参数(文件名、 fileobj, title, description, tags),我只传递了四个,因为 fileobj 是可选的。

我已经用谷歌搜索了一些示例,但我找不到可以解决问题的方法。所以,任何帮助都会很棒。

问候,

马西奥

【问题讨论】:

    标签: python-3.x flickr


    【解决方案1】:

    我找到了解决方案,并在此分享。我的代码有两个问题。

    首先:我们必须使用 kwargs;第二:标签必须用空格隔开,不能用逗号

    这里是最终版本:

    import flickrapi
    
    api_key = u'xxxxxxxxxxxxxxxxxxxxxxxx'
    api_secret = u'xxxxxxxxxxxxxxxxxxxx'
    
    flickr = flickrapi.FlickrAPI(api_key, api_secret)
    
    params = {}
    params['filename'] = 'd:/downloads/_D4_6263-Enhanced.png'
    params['title'] = 'Fach Halcones'
    params['description'] = 'Posting image using API'
    params['tags'] = '''fidae aviation extra "air shows" '''
    flickr.upload(**params)
    

    就是这样……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-14
      • 2013-08-23
      • 2011-06-04
      • 2017-02-18
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多