GoogleドライブのREST APIインターフェイスで苦労しています。 プログラムでフォルダを作成する必要があります。 apiドキュメント(https://developers.google.com/drive/v3/reference/files/create)を読むと、POSTメソッドを持つフォルダをhttps://www.googleapis.com/drive/v3/filesに、フォルダ名とMIMEタイプを 'application/vnd.google-apps.folder'とするリクエスト本体にすることができます残りのAPIインターフェイスとPythonリクエストを使用してGoogleドライブにフォルダを作成します
このpython関数を書くこのような応答オブジェクト出力
def createFolder(self,folderName):
if not self.authorization:
self.get_authorization()
url = 'https://www.googleapis.com/drive/v3/files'
headers = { 'Authorization':'Bearer {}'.format(self.access_token)}
metadata = {
"name": folderName,
"mimeType": 'application/vnd.google-apps.folder'
}
response = requests.post(url, headers = headers, params = metadata)
return response.json()
:
{
u'mimeType': u'application/json',
u'kind': u'drive#file',
u'id': u'0B350e2U7rvyvR0k3NjJmTTVuWUE',
u'name': u'Untitled'
}
ファイルが作成されますが、フォルダのメタデータが適用されません。 「試してみよう! API Explorer私は正しい動作をするので、私のコードがどこで間違っているのか理解できません。
私は移植可能なプラグインを書いています。私はGoogleライブラリを扱いたくないので、単純なHttpアプローチが好きです。
私に何か提案をいただければ幸いです。
他のPythonモジュールを使用できますか?私は 'pydrive'を使ってGoogleドライブとのやりとりを成功させました。 – asongtoruin
私は依存関係を避けるでしょう。 http://stackoverflow.com/questions/23594515/python-request-for-google-drive –