I'm trying to connect google sheets with python using gspread library.
I have tried a ginormous set of using examples of gspread, for no avail. I have also used google official libraries with the same tsunami of disappointment and despair (actually google code leads to a authentication page under terminal that doesn't work "because javascript is not enabled in your, well, browser")
my example code:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile.name('client_secret.json', scope)
gc = gspread.authorize(credentials)
hoja = gc.open('testpy').sheet1
print(hoja.get_all_records())
client.secret.json
is renamed from secrey key json file obtained from service account credentials. it is something like this
{
"type": "service_account",
"project_id": "personaltestpygshee6",
"private_key_id": "29etcetc",
"private_key": "-----BEGIN PRIVATE KEY-----\netcetc\n-----END PRIVATE KEY-----\n",
"client_email": "project@project.iam.gserviceaccount.com",
"client_id": 423etcetc",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/project%40project.iam.gserviceaccount.com"
}
when I run the script, this is the error message that I obtain
File "5testgooshee.py", line 6, in <module>
credentials = ServiceAccountCredentials.from_json_keyfile.name('client_secret.json', scope)
AttributeError: type object 'ServiceAccountCredentials' has no attribute 'from_json_keyfile'
I have done my homework, I swear. Steam comes out of my ears. I cannot figure out what is the problem and why it works in a lot of examples except mine
Where is the failure? Why I cannot make it work?
Thanks in advance