Python用Picasa E创建相册

2024-09-30 08:26:39 发布

您现在位置:Python中文网/ 问答频道 /正文

(我们需要从以前的cd2改为Google)。在

我可以成功地访问相册并阅读照片上的数据/评论。当我尝试添加新的相册/照片或试图写入数据时,我得到以下错误。在

    client = PhotosService(email="xxxx")    
   ...
   ...
   ...
   #After successfull OAuth 
   album = client.InsertAlbum(title="Temp album", summary="My summary", access="public")

此行导致以下错误。在

^{pr2}$

Tags: 数据clientalbumemail错误google评论summary
1条回答
网友
1楼 · 发布于 2024-09-30 08:26:39

我不太确定,但你真的改变了OAuth2吗?我使用了下面的代码,它成功了。在

def OAuth2Login(client_secrets, credential_store, email):
scope='https://picasaweb.google.com/data/'
user_agent='testingApp'

storage = Storage(credential_store)
credentials = storage.get()
if credentials is None or credentials.invalid:
    flow = flow_from_clientsecrets(client_secrets, scope=scope, redirect_uri='urn:ietf:wg:oauth:2.0:oob')
    uri = flow.step1_get_authorize_url()
    webbrowser.open(uri)
    code = raw_input('Enter the authentication code: ').strip()
    credentials = flow.step2_exchange(code)
    storage.put(credentials)

if (credentials.token_expiry - datetime.utcnow()) < timedelta(minutes=5):
    http = httplib2.Http()
    http = credentials.authorize(http)
    credentials.refresh(http)

gd_client = gdata.photos.service.PhotosService(source=user_agent,
                                           email=email,
                                           additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})

return gd_client
album = gd_client.InsertAlbum('test', 'My Test Album', access='protected')

我确实需要在googledeveloper门户中创建一个API密钥并下载json密码,但是在这样做之后,我成功地创建了一个相册。这次回购非常有用https://github.com/MicOestergaard/picasawebuploader。在

相关问题 更多 >

    热门问题