文件:插入 - Google Drive SDK - Python示例 - 什么是Drive API服务实例? [英] Files:insert - Google Drive SDK - Python Example - What is Drive API service instance?

查看:196
本文介绍了文件:插入 - Google Drive SDK - Python示例 - 什么是Drive API服务实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

USING :Windows7,Python 2.7,Google App Engine



Google使用Python将文件插入(创建) Drive API。以下是显示页面底部附近代码的链接:



使用Python将文件写入Google Drive



一个名为 insert_file 定义在Python模块中。

  def insert_file(service,title,description,parent_id,mime_type,文件名):

insert_file 函数需要6参数传递给它。第一个参数是 service



在示例代码的注释部分,表明 service arg以 Drive API服务实例作为输入。


参数:

 服务:云端硬盘API服务实例。 
title:要插入的文件的标题,包括扩展名。
描述:要插入的文件的描述。
parent_id:父文件夹ID。
mime_type:要插入的文件的MIME类型。
filename:要插入的文件的文件名。


什么是 Drive API服务实例?我不知道那是什么或有效的设置。它是以URL表示的授权范围吗?我知道 title description 是什么。标题是正在编写的文件的新名称,描述是详细信息,可能放入文件元数据中。我不确定如何获取 parent_id 父文件夹。这些信息如何获得?我是否从Google云端硬盘手动获取?我知道什么是MIME类型设置。

如果有人可以给出 Drive API服务实例的解释,并举例说明,很棒。我搜索了 Drive API服务实例,并找不到解释。我搜索了互联网。我搜索了Google Developers。我找不到任何东西。

解决方案

服务是您想要实例化的API服务。有很多服务。应用可以与Google地图或Google任务,电子邮件或云端硬盘进行通信。

用于Python的Google API

所以,服务是 API服务。构建实例化API服务。这是从视频,分钟12:46。

Google Drive API服务的YouTube示例



我在文档中发现了一些关于父文件夹的内容。
Google Drive API



Google Drive API有一个 files:insert API。 文件:insert API使用各种参数发出请求。这就是所谓的请求正文,它有自己的参数。 Request Body的参数之一是 parents [] 。它是一个可选参数。对于 insert ,如果 parents [] 参数为空,则会在用户根目录中创建该文件。所以,我想如果你想把文件写入一个特定的文件夹,你需要给父母[]参数一个名字。我假设这是 insert_file 函数中的 parent_id arg,但我不确定。我需要看看实际的功能,但没有给出。

Parent ID 上搜索后,它看起来就是文件夹ID。当您转到Google云端硬盘并点击文件夹时,浏览器地址栏中的网址会发生变化。只需点击该文件夹,网址将如下所示:



https://drive.google.com/?tab=wo& authuser = 0#folders / 0B52YKjuEE44yUVZfdDNzNnR3SFE



parentID 结束正斜杠后。



我想我需要再次查看Google Quickstart文件。



至少有三个例子是我找到的:


  • 快速入门例。 Google Drive SDK

  • Dr编辑。 Google Drive SDK示例

  • 另一个快速入门示例< a href =https://developers.google.com/api-client-library/python/apis/drive/v2 =nofollow> Google Drive API



第一个是simpliest。编辑博士可能是最多的文件?最后一个看起来像是更新的?我不知道。这对使用哪个示例感到困惑。 Drive SDK 和Drive API 示例仅处理某个外部应用的帐户授权以访问用户帐户。


USING: Windows7, Python 2.7, Google App Engine

Google's documentation for inserting(creating) a file to Google Drive using Python and the Drive API. Here is the link showing the code near the bottom of the page:

Write a file to a Google Drive using Python

A function named: insert_file is defined in the Python module.

def insert_file(service, title, description, parent_id, mime_type, filename):

The insert_file function takes 6 arguments passed into it. The first arg is service.

In the comment section of the example code, it is indicated that the service arg takes the Drive API service instance as the input.

Args:

service: Drive API service instance.
title: Title of the file to insert, including the extension.
description: Description of the file to insert.
parent_id: Parent folders ID.
mime_type: MIME type of the file to insert.
filename: Filename of the file to insert.

What is the Drive API service instance? I have no idea what that is or what the valid settings are. Is it the authorization scope that is expressed as a URL? I do know what the title and description are. The title is the new name of the file being written, and the description is a detail, presumably put into the files metadata. I'm not sure how to get the parent_id or the Parent folder either. How is that info obtained? Do I get that manually from Google Drive? I know what the MIME type setting is.

If someone could give an explanation of what the Drive API service instance is, and give an example, that would be great. I did a search for Drive API service instance, and couldn't find an explanation. I searched the internet. I searched Google Developers. I found nothing.

解决方案

The service is the API service that you want to instantiate. There are lots of services. An app can communicate with Google Maps, or Google tasks, or email, or Drive.

Google API's for Python

So, the service is the API service. Build instantiates the API service. This is from the video, minute 12:46.

YouTube example for Google Drive API Service

I found something about Parent Folders in the documentation. Google Drive API

The Google Drive API has a files:insert API. The files:insert API makes a request with various parameters. There is, what is called, the Request body which has it's own parameters. One of the parameters for the Request Body is parents[]. It is an optional parameter. For insert, if the parents[] parameter is blank, the file gets created in the users root directory. So, I guess if you want the file to be written to a particular folder, you need to give the parents[] parameter a name. I'm assuming that is what the parent_id arg in the insert_file function is for, but I'm not sure. I need to look at the actual function, but that's not given.
After doing searches on Parent ID it looks like that is the folder ID. When you go to your Google Drive, and click on a folder, the URL in the browsers address field changes. Just click on the folder and the URL will look something like this:

https://drive.google.com/?tab=wo&authuser=0#folders/0B52YKjuEE44yUVZfdDNzNnR3SFE

The parentID is the long part on the end after the forward slash.

I guess I need to look at the Google Quickstart files again.

There are at least three examples that I've found:

The first one is the simpliest. Dr Edit has the most files maybe? The last one looks like its more current? I don't know. It's kind of confusing about which example to use. The Drive SDK and the Drive API examples only deal with authorization of an account for some outside app to access a users account.

这篇关于文件:插入 - Google Drive SDK - Python示例 - 什么是Drive API服务实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆