Comments (19)
Unfortunately then you have to use the gdata python client library. I agree that it would be nice to have this feature in gspread and hopefully it will eventually make it. Luckily for my current projects I do not need this capability.
However this might be a good reference as well as the text_db library which is similar to this one, but this one appears to be more actively maintained.
I wish I was a better programmer and had more time to support this project as I would like to see it improve faster. Maybe I can start throwing some donations out to help move it along.
from gspread.
Here is updated example for oauth2client
version 2.0:
https://gist.github.com/miohtama/f988a5a83a301dd27469
I am wiling to incorporate this to Client
class if there is green light for this.
The only question is if one wants to have Google Data API for Python as a dependency or not. Looks like accomplishing this with requests and pure REST API would not be too complex either.
from gspread.
Hi there! Thanks for warm feedback :)
There's no straight-ahead way to accomplish this via current Google API, but I'll see what I can do.
from gspread.
It says possible by uploading a blank document via Google Documents List API..
from gspread.
Any updates on this? This would be a nice feature...
UPDATE: After scouring the web for this, and searching through the very limited GData Python Documentation, I've finally figured out how to create new spreadsheets. It requires the GData-Python-Client API (https://code.google.com/p/gdata-python-client/). You then use gdata.docs.client to create a new resource of the type "spreadsheet". I've pasted my code here for anyone who's also looking for this feature. The code tries to open a given file name, and if it doesn't exist, it creates the new file. For those interested in just creating new spreadsheets, the code to look at is in the 'except' section.
http://pastebin.com/zADrcEJU
from gspread.
Hey Burnash,
Splendid work you are accomplishing on the GSpread library.
I currently work for Google and am working on a project to automatically update a ACL per google spreadsheet.
The only functionality I need currently is to be able to download the original sheet via TSV , text / tab space value, then manipulate this information via a bash script, and re-upload the new contents via GSpread.
If there is already a way to accomplish this please let me know.
Best Regards.
from gspread.
I'm working with the Google Drive API that has features to create, copy, rename and delete files (spreadsheets too), but the OAuth2 method is very tangled. When I have results I will share it.
from gspread.
Here's how you create a document with the gdata api. The docs are absolutely terrible. Literally took me three hours to figure out. The third argument to the login method is supposed to be the "source." No idea what that is supposed to mean but any non-empty string will work here.
import gspread
import gdata.docs.client
docs_client = gdata.docs.client.DocsClient()
docs_client.ClientLogin('[email protected]', 'Pikachu', 'Any non empty string')
document = gdata.docs.data.Resource(type='spreadsheet', title='my_spreadsheet')
resource = gd_client.CreateResource(document)
full_id = resource.resource_id.text # returned by gdata
gs_api = gspread.login('[email protected]', 'Pikachu')
gs_id = full_id[len('spreadsheet:'):] # reformat id so gspread can understand
gs_api.open_by_key(gs_id)
And to copy an existing document:
docs_client = gdata.docs.client.DocsClient()
docs_client.ClientLogin('[email protected]', 'Pikachu', 'Any non empty string')
base_resource = docs_client.GetResourceById(resource_id)
new_resource = docs_client.copy_resource(base_resource, 'pokedex')
from gspread.
Thanks, adamruhl, for the extremely useful info!
Is there a way to use docs_client.ClientLogin with OAuth credentials - or otherwise copy an existing sheet with them? I've been digging around the docs forever, too, and haven't had much luck.
Or maybe something with construct_url provided here?
from gspread.
I figured out a way to do it with google-api-python-client. Hopefully, it will be helpful to others:
import httplib2
from apiclient import errors
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
to_copy = '<id/key_string_from_desired_file_url>'
# Service account e-mail from Google dev console
drive_id = '<my_long_service_account_string>@developer.gserviceaccount.com'
# Get the right permissions
drive_scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
# pem key converted from p12 key generated in dev console
with open(os.path.abspath('my_key.pem'), 'rb') as keyfile:
drive_key = keyfile.read()
credentials = SignedJwtAssertionCredentials(drive_id, drive_key, drive_scope)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
file_copy = {'title': title}
try:
drive_service.files().copy(fileId=to_copy, body = file_copy).execute()
except errors.HttpError, error:
print error
from gspread.
Is it just me, or is the Google gdata API incredibly confusing? To compound matters, its documentation is horrible. And further more, all of the examples found no longer are functional due to API changes. For instance, the above gdata example from @adamruhl gives the error: "The Doclist API has been shut down. Please use the new Drive API, https://developers.google.com/drive/."
Can someone recommend the easiest way, one that works, for creating a new sheet? Cheers.
from gspread.
That would be a pretty nice feature.
from gspread.
Hi @00gavin and @herrsergio
Take a look on df2gspread library, which provides this possibility!
from gspread.
@miohtama Please do it. I'm not @burnash but this would be really helpful.
I'm going to look at your linked example and see if I can do it manually :/
from gspread.
@fialovy, why have you used self? Your code is not working, gives error for "self"
from gspread.
@patelnidhice I wrote the code within a class and modified things after paste; will edit
from gspread.
Thanks @fialovy, need help here.
SignedJwtAssertionCredentials doesn't work.
This is my code which I am trying to run:
import webapp2
from oauth2client.service_account import ServiceAccountCredentials
import gspread
from apiclient.discovery import build
import os
import httplib2
SCOPES = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('myabc.json', SCOPES)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
file_copy = {'title': "new_copy"}
to_copy = 'x/something'
drive_id = '[email protected]'
drive_scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
drive_service.files().copy(fileId=to_copy, body = file_copy).execute()
Getting error:
drive_service.files().copy(fileId=to_copy, body = file_copy).execute()
File "/usr/lib/python2.7/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/usr/lib/python2.7/site-packages/googleapiclient/http.py", line 832, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/< abc >/copy?alt=json returned "Insufficient Permission">
Can someone please help in resolving this issue?
from gspread.
I am able to copy spreadsheet, but unable to open it, and also can't see the location also. I am using gmail account for original spreadsheet, same I want to copy. Not sure why it is asking for permission, is there any way to handle this? Please help.
from gspread.
Added in #253
from gspread.
Related Issues (20)
- Update conda forge package HOT 2
- A way to add DataValidation HOT 6
- Missing py.typed marker HOT 1
- AttributeError: 'HTTPClient' object has no attribute 'import_csv' HOT 3
- Unable to read public readonly spreadsheet HOT 4
- Add missing types HOT 2
- Disambiguating and filling in headers similar to Pandas HOT 8
- worksheet.add_protected_range() - impossible to create the `warning_only=True` range HOT 2
- ADC Authentication HOT 2
- HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1000)'))) HOT 2
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- gspread depends on google-auth>2.4.0 but only specifies google-auth>=1.12.0 HOT 7
- Client.copy(..., copy_permissions=True) breaks when permission type is domain HOT 1
- Remove StrEnum dependency HOT 6
- Add support for append columns HOT 5
- Feature request. Batch Merge in worksheet class HOT 4
- lint failure HOT 1
- get_notes from a range HOT 3
- check Spinx will work with RTD
- Exception requests.exceptions.JSONDecodeError is raised in APIError constructor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gspread.