Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google Drive API权限,如何禁用Internet上任何人都可以查找的功能?_Python_Google Api_Google Drive Api_Google Api Python Client_Pydrive - Fatal编程技术网

Python Google Drive API权限,如何禁用Internet上任何人都可以查找的功能?

Python Google Drive API权限,如何禁用Internet上任何人都可以查找的功能?,python,google-api,google-drive-api,google-api-python-client,pydrive,Python,Google Api,Google Drive Api,Google Api Python Client,Pydrive,我搜索谷歌,但没有结果,我的代码如下: import sys reload(sys) sys.setdefaultencoding("utf-8") from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive # this function used inside function do_the_work(drive) def upload_gd(media_file, drive): print

我搜索谷歌,但没有结果,我的代码如下:

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

# this function used inside function do_the_work(drive)
def upload_gd(media_file, drive):
    print 'Try uploading ' + media_file

    xfile = drive.CreateFile()
    xfile.SetContentFile(media_file)
    xfile.Upload()
    print('Created file %s with mimeType %s' % (xfile['title'], xfile['mimeType']))

    permission = xfile.InsertPermission({
        'type': 'anyone',
        'value': 'anyone',
        'role': 'reader'})

    print 'Sharable link (to view) is:' + xfile['alternateLink']
    print 'Get direct link'
    file_id = xfile['alternateLink'].split('/')[-2]
    print 'file ID: ' + file_id
    d_link = 'https://drive.google.com/uc?export=download&id=' + file_id
    print 'Direct link is: ' + d_link

    return d_link

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)
do_the_work(drive)
并且,我获得的文件权限是:



但是,我只希望任何人都可以查看,但不能查找为:

使用该语句,实际上就是将文件设置为公共只读。公共只读是互联网上每个人都可以阅读的


回答:如果您不想让internet上的任何人能够找到或查看该文件,请将类型设置为
、或
用户
,或者更好地设置您希望查看该文件的人的电子邮件地址的值。

您需要添加
with link
字段:

permission = xfile.InsertPermission({'type': 'anyone',
                                     'value': 'anyone',
                                     'role': 'reader',
                                     'withLink': True})  # <-- This field.
permission=xfile.InsertPermission({'type':'any',
“值”:“任何人”,
“角色”:“读者”,

“withLink”:True})#注意,pydrive当前正在使用驱动api v2Yep,谢谢@BùiVănThủ 为了突出这一点。上面指定的链接指向v2-I,我编辑了这篇文章以澄清这一点:)
permission = xfile.InsertPermission({'type': 'anyone',
                                     'value': 'anyone',
                                     'role': 'reader',
                                     'withLink': True})  # <-- This field.