2015-05-29 75 views
1

Google最近转移到了OAuth2.0,我们需要更改之前的身份验证方式(即从ProgrammaticLoginOAuth2.0)。Python - 使用Picasa创建相册错误

我可以成功访问相册和读取照片数据/评论。当我尝试添加新相册/照片或尝试写入数据时,出现以下错误。

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

此行会导致以下错误。

File "/Users/mac/destipak/env/lib/python2.7/site-packages/gdata/photos/service.py", line 358, in InsertAlbum 
    raise GooglePhotosException(e.args[0]) 
gdata.photos.service.GooglePhotosException: (403, 'Forbidden', 'Modification only allowed with api authentication.') 

回答

0

我不太确定,但是您是否实际上对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') 

我确实有建立在谷歌开发者门户网站的API密钥和下载json的秘密,但这样做,我是能够成功地创建相册后。这个回购非常有帮助https://github.com/MicOestergaard/picasawebuploader