1

我正在尝试使用 google docs api (python) 创建集合和子集合,并在创建的子集合中上传文件。

第一个问题:下面的代码一切正常,层次结构正常(文件夹1下的子文件夹1,子文件夹1下的上传文件),但唯一的问题是最终用户的主页中也可以看到子文件夹和文件。我只想在 Home 中看到更高级别的集合。

有没有办法阻止资源(子集合和文件)显示在 Home 中?

注意:我尝试了以下替代方法,但仍然得到相同的结果:1)create_resource 的参数 'collection=' 具有相同的结果 2)cli​​entlogin 或 twoleggedoauth 具有相同的结果

第二个问题: 是否可以设置描述字段?

import gdata.data
import gdata.docs.client
import gdata.acl.data
import gdata.docs.data

GAPPS_OAUTH_CONSUMER_KEY = "xxxx"
GAPPS_OAUTH_CONSUMER_SECRET = "xxxxx"
GAPPS_ADMIN_ACCOUNT = "x"

GAPPS_CLIENT_LOGIN_LOGIN='xxxxx'
GAPPS_CLIENT_LOGIN_PWD='xxxxx'
GAPPS_CLIENT_LOGIN_APP='xxxxxx'

filepath = 'C:\\Users\\xxxxx\\Pictures\\'
filename = 'xxxxxx.png'

path = filepath + filename

client = gdata.docs.client.DocsClient()
client.ssl = True
#client.ClientLogin(GAPPS_CLIENT_LOGIN_LOGIN, GAPPS_CLIENT_LOGIN_PWD, GAPPS_CLIENT_LOGIN_APP)
client.auth_token = gdata.gauth.TwoLeggedOAuthHmacToken(GAPPS_OAUTH_CONSUMER_KEY, GAPPS_OAUTH_CONSUMER_SECRET, GAPPS_ADMIN_ACCOUNT)

# create a folder

collection1 = gdata.docs.data.Resource('folder', title = 'Script Folder')
collection1 = client.create_resource(collection1)

# create a sub-folder in collection1

subcollection1 = gdata.docs.data.Resource('folder', title = 'Script Sub Folder')
subcollection1 = client.create_resource(subcollection1)

res = client.move_resource(subcollection1, collection = collection1, keep_in_collections = False)

# Upload the resource in subcollection1

doc = gdata.docs.data.Resource(type = 'file', title = filename)
media = gdata.data.MediaSource()
media.SetFileHandle(path, 'application/octet-stream')
create_uri = gdata.docs.client.RESOURCE_UPLOAD_URI + '?convert=false'
doc = client.CreateResource(doc, create_uri = create_uri, media = media)
print 'Created, and uploaded:', doc.title.text, doc.resource_id.text

client.move_resource(doc, collection = subcollection1, keep_in_collections = False)
4

2 回答 2

1

这是解决方案:

subcollection1 = gdata.docs.data.Resource('folder', title = 'Script Sub Folder')
subcollection1.AddCategory(gdata.docs.data.LABELS_NS, gdata.docs.data.LABELS_NS + "#" +gdata.docs.data.HIDDEN_LABEL, gdata.docs.data.HIDDEN_LABEL)
subcollection1 = client.create_resource(subcollection1)
于 2012-05-31T07:54:58.707 回答
0

还有另一种更简单的方法。

subcollection1 = client.create_resource(subcollection1,collection=collection1)

通过这种方法,脚本子文件夹永远不会出现在您的根文件夹中。

于 2013-07-11T06:57:16.363 回答