Taki oto (uproszczony) skrypt basha używałem do niedawna do wysyłania plików na konto Picasaweb (por. Using cURL to interact with Google Data services oraz PicasaUploader):
USERNAME=SomeUsername # GoogleAccountUsername
PASSWORD=SomePasswd # GoogleAccountPasswd
ALBUM_ID=6008849823888405298 # ID of picasaweb album
MY_PIC="$1" ## filename of the picture to upload ##
PIC_TITLE=`basename $MY_PIC` # filename w/o extension
PIC_TYPE=`file -b --mime-type "$MY_PIC"`
AUTH_KEY=$( curl -s https://www.google.com/accounts/ClientLogin -d Email="$USERNAME"@gmail.com \
-d Passwd="$PASSWORD" -d accountType=GOOGLE \
-d source=Google-cURL-Example -d service=lh2 | awk -F\= '/^Auth=/{print $2}' )
ALBUM_XML="http://picasaweb.google.com/data/feed/api/user/$USER_ID/albumid/$ALBUM_ID?authkey=$AUTH_KEY"
URL=`curl -s --request POST --data-binary "@$MY_PIC" --header "Slug: $PIC_TITLE" \
--header "Content-Type: $PIC_TYPE" \
--header "Authorization: GoogleLogin auth=$AUTH_KEY" "$ALBUM_XML" | \
sed 's/.*media:content url='"'"'\([^'"'"']*\).*media:thumbnail url='"'"'\([^'"'"']*\).*/\1/'`
Zmienna URL zawiera url wysłanego na Picasaweb obrazka (otrzymany
przez zaaplikowanie w potoku odpowiedniego skryptu seda).
Skrypt przestał działać ostatnio, ponieważ Google nie obsługuje już protokołu OAuth 1.0 (por. Google Identity Platform). Na szczęście w łatwy sposób możliwe było dopasowanie skryptu nowszego protokołu OAuth 2.0:
ACCESS_TOKEN=$(oauth2picasa.py) ## Acces token is managed with Python's script now ## Note that ALBUM_XML URL starts now from https:// now ALBUM_XML="https://picasaweb.google.com/data/feed/api/user/$USER_ID/albumid/$ALBUM_ID" URL=`curl -s --request POST --data-binary "@$MY_PIC" \ --header "GData-Version: 2" --header "Slug: $PIC_TITLE" \ --header "Content-Type: $PIC_TYPE" -H "Authorization: Bearer $ACCESS_TOKEN" $ALBUM_XML | \ sed 's/.*media:content url='"'"'\([^'"'"']*\).*media:thumbnail url='"'"'\([^'"'"']*\).*/\1/'`
Uwaga: Autoryzację OAuth 2.0 obsługuje Pythonowy skrypt oauth2picasa.py.
Skrypt jest (zapożyczonym) fragmentem z projektu
picasawebsync:
#!/usr/bin/python
import os
import time
import httplib2
## https://github.com/google/oauth2client
## installed with pip install --upgrade oauth2client (or some other way)
from oauth2client import client
def oauthLogin():
# using http://stackoverflow.com/questions/20248555/list-of-spreadsheets-gdata-oauth2/29157967#29157967
from oauth2client.file import Storage
filename = os.path.join(os.path.expanduser('~'), ".picasawebsync")
client_secrets = os.path.join(os.path.expanduser('~'), ".config", "picasawebsync.json")
storage = Storage(filename)
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = client.flow_from_clientsecrets(client_secrets,
scope='https://picasaweb.google.com/data/',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
print 'Authorization URL: %s' % auth_uri
auth_code = raw_input('Enter the auth code: ')
credentials = flow.step2_exchange(auth_code)
storage.put(credentials)
if credentials.access_token_expired:
credentials.refresh(httplib2.Http())
return credentials.access_token
# start of the program
gd_client = oauthLogin()
print '%s' % gd_client
Jak stworzyć OAuth 2.0 client ID opisano
tutaj.
Należy wybrać Client ID for native application. Następnie należy pobrać plik JSON,
zmienić nazwę tego pliku na
picasawebsync.json umieszczając go w katalogu .config
swojego katalogu domowego (albo zmodyfikować skrypt, jeżeli plik ma być w innym miejscu).
Uruchomiony po raz pierwszy skrypt oauth2picasa.py wypisuje URL, który należy
skopiować/wkleić do przeglądarki, celem uzyskania authcode.
Pobrany authcode
wklejamy w odpowiedzi na prompt Enter the auth code:.
Opisane skrypty są tutaj: picasa_upld.sh
oraz oauth2picasa.py.
raise InvalidClientSecretsError('File not found: "%s"' % filename)
OdpowiedzUsuńHow is client_secrets supposed to be written? This seems to be missing something.
Hi, there is english version of this post:
OdpowiedzUsuńhttp://pinkaccordions.blogspot.com/2015/06/uploading-pictures-to-picasaweb-with.html
Have you read it?
File not found? One have to create an OAuth 2.0 client ID in the Google Developers Console
and then download (from Google Developers Console) a JSON file to appropriate location ~/.config (or modify the script)...