2010-03-03 23 views
0

我有一個Web應用程序,我想與Flickr同步。我不希望用戶必須登錄到Flickr,所以我打算使用單一登錄。我相信我需要這樣做:使用Python庫的Flickr API自動登錄flickrapi

import flickrapi 
flickr = flickrapi.FlickrAPI(myKey, mySecret) 
(token, frob) = flickr.get_token_part_one(perms='write', my_auth_callback) 
flickr.get_token_part_two((token, frob,)) 
flickr.what_have_you(... 

我不知道my_auth_callback應該看起來像什麼。我懷疑它將不得不將我的登錄信息發佈到flickr。我可以隻手動執行一次get_token_part_one步驟,然後在get_token_part_two中重新使用它嗎?

編輯

Wooble有它。以下是我使用Django shell和flickrapi庫寫下的一些明確方向。

import flickrapi 
api_key = "xxxx...xxxx" 
api_secret = "xxxx...xxxx" 
_flickr = flickrapi.FlickrAPI(api_key, api_secret) 
_flickr.web_login_url("write") 
# Go to that url. 
# That sends you back to the callback url you set by "editing the 
# authentication workflow" on your flicks admin page located on the site. 
# This callback url will contain a frob in the form 
# xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xxxxxxxx 
_flickr.get_token("xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xxxxxxxx") 
# That returns the token. Then test with 

import flickrapi 
from django.conf import settings 
_flickr = flickrapi.FlickrAPI(api_key, api_secret, token=api_token) 
_flickr.groups_pools_getGroups() 

回答

1

如果您不希望用戶使用Flickr進行身份驗證,則根本不需要使用獲取令牌的代碼。只需爲自己獲取一個令牌,並將其包含在代碼中即可。

請注意,使用您自己的帳戶「同步」其他用戶的照片可能會破壞Flickr的服務條款。

+0

我一直無法「只爲自己獲得一個令牌」,儘管我已經嘗試了一段時間,使用手動和Python兩種方法。任何人有任何實際的建議或代碼? – 2010-03-03 17:13:38

+0

我收到很多「錯誤:108:無效的光環」 – 2010-03-03 17:16:29

+0

您是否閱讀過flickr的auth文檔?你只需要調用flickr.auth.getFrob,在Flickr上訪問正確的頁面來授權它,然後使用第一次調用的frob調用flickr.auth.getToken。如果您確實想讓您的用戶像您一樣進行身份驗證,則返回的令牌可以作爲字符串嵌入您的應用程序中。 – geoffspear 2010-03-04 01:14:41