GithubHelp home page GithubHelp logo

Comments (19)

TravisJoe avatar TravisJoe commented on August 24, 2024 1

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.

miohtama avatar miohtama commented on August 24, 2024 1

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.

burnash avatar burnash commented on August 24, 2024

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.

ramshankerji avatar ramshankerji commented on August 24, 2024

It says possible by uploading a blank document via Google Documents List API..

from gspread.

yaktwok avatar yaktwok commented on August 24, 2024

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.

scrathjen avatar scrathjen commented on August 24, 2024

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.

SalvaJ avatar SalvaJ commented on August 24, 2024

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.

adamruhl avatar adamruhl commented on August 24, 2024

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.

fialovy avatar fialovy commented on August 24, 2024

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.

fialovy avatar fialovy commented on August 24, 2024

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.

00gavin avatar 00gavin commented on August 24, 2024

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.

herrsergio avatar herrsergio commented on August 24, 2024

That would be a pretty nice feature.

from gspread.

maybelinot avatar maybelinot commented on August 24, 2024

Hi @00gavin and @herrsergio
Take a look on df2gspread library, which provides this possibility!

from gspread.

Ralithune avatar Ralithune commented on August 24, 2024

@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.

crick231 avatar crick231 commented on August 24, 2024

@fialovy, why have you used self? Your code is not working, gives error for "self"

from gspread.

fialovy avatar fialovy commented on August 24, 2024

@patelnidhice I wrote the code within a class and modified things after paste; will edit

from gspread.

crick231 avatar crick231 commented on August 24, 2024

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.

crick231 avatar crick231 commented on August 24, 2024

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.

burnash avatar burnash commented on August 24, 2024

Added in #253

from gspread.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.