使用 Python API,我创建了一个导出。如何使用相同的授权服务下载导出中的 .zip 文件?创建导出时,我可以看到 cloudStorageSink 的 bucketName 和 objectNames,但是我找不到有关如何使用创建导出的现有服务将它们下载到我的主机的任何文档
#!/usr/bin/env python
from __future__ import print_function
import datetime
import json
import time
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# If modifying these scopes, delete the file token.json.
SCOPES = 'https://www.googleapis.com/auth/ediscovery'
def list_exports(service, matter_id):
return service.matters().exports().list(matterId=matter_id).execute()
def get_export_by_id(service, matter_id, export_id):
return service.matters().exports().get(matterId=matter_id, exportId=export_id).execute()
def get_service():
'''
Look for an active credential token, if one does not exist, use credentials.json
and ask user for …Run Code Online (Sandbox Code Playgroud) 我需要通过 Python 将 Google Cloud Storage 中的一些文件从一个文件夹移动到另一个文件夹。查看他们的文档,我似乎找不到任何可以移动实际文件的内容,我需要将文件复制到另一个目录,然后删除原始文件。
我能够找到copy_blob,但是,我无法在其中看到任何可以指定文件夹的内容。有没有办法指定我也想复制文件的文件夹?还是有另一种方法可以将文件从一个文件夹移动到另一个文件夹?
python google-cloud-storage google-api-python-client google-cloud-platform
我正在尝试使用 google 客户端 api 从 python 脚本更新文件的内容。问题是我一直收到错误 403:
An error occurred: <HttpError 403 when requesting https://www.googleapis.com /upload/drive/v3/files/...?alt=json&uploadType=resumable returned "The resource body includes fields which are not directly writable.
Run Code Online (Sandbox Code Playgroud)
我试图删除元数据字段,但没有帮助。
更新文件的函数如下:
# File: utilities.py
from googleapiclient import errors
from googleapiclient.http import MediaFileUpload
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
def update_file(service, file_id, new_name, new_description, new_mime_type,
new_filename):
"""Update an existing file's metadata and content.
Args:
service: Drive API service instance.
file_id: ID of the file …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Google API Python 客户端和服务帐户身份验证来访问我们的 GSuite GMail API。根据文档,我的 MCVE 代码如下:
import os
import sys
from google.auth.transport.requests import Request
from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
email = sys.argv[1]
cred = Credentials.from_service_account_file(os.getenv('SERVICE_ACCOUNT'))
cred = cred.with_scopes(['https://www.googleapis.com/auth/gmail.labels'])
cred.refresh(Request())
gmail = build('gmail', 'v1', credentials=cred)
try:
print(gmail.users().labels().list(userId=email).execute())
except Exception as ex:
print('Error:', ex.content.decode('ascii'))
Run Code Online (Sandbox Code Playgroud)
输出是:
Error: {
"error": {
"errors": [
{
"domain": "global",
"reason": "failedPrecondition",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
Run Code Online (Sandbox Code Playgroud)
普通嫌疑犯:
我目前正在尝试使用 pyinstaller 构建一个应用程序。我得到了错误The 'google-api-python-client' distribution was not found and is required by the application,我完全不知道为什么。
运行pip show google-api-python-client结果
Name: google-api-python-client
Version: 1.8.2
Summary: Google API Client Library for Python
Home-page: http://github.com/google/google-api-python-client/
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: c:\dev\software\schoology_scrape\schoology_scrape_venv\lib\site-packages
Requires: google-auth-httplib2, uritemplate, google-auth, google-api-core, httplib2, six
Required-by:
Run Code Online (Sandbox Code Playgroud)
我还有一个 requirements.txt 文件,其中包含项目中使用的所有库
任何帮助将不胜感激!
我一直在使用 youtube API 远程上传。但是经过一段时间的代码处理后,由于条款和政策,所有上传的视频都被“私有(锁定)”。由于“无法针对此违规行为提出申诉”,我无法对其提出申诉。只是为了澄清我之前已经能够上传并且最近才开始出现此错误。
代码:youtube-uploader
#!/usr/bin/python
import argparse
import http.client
import httplib2
import os
import random
import time
import videoDetails
import google.oauth2.credentials
import google_auth_oauthlib.flow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload
from google_auth_oauthlib.flow import InstalledAppFlow
from oauth2client import client # Added
from oauth2client import tools # Added
from oauth2client.file import Storage # Added
# Explicitly tell the underlying HTTP transport library not to retry, since
# we …Run Code Online (Sandbox Code Playgroud) python google-api python-3.x google-api-python-client youtube-data-api
我已经在谷歌云中部署了一个 python 3.7 函数。我需要通过代码获取 project-id 以找出它的部署位置。
我写了一个小的python 3.7脚本并通过google shell命令行对其进行测试
import urllib
import urllib.request
url="http://metadata.google.internal/computeMetadata/v1/project/project-id"
x=urllib.request.urlopen(url)
with x as response:
x.read()
Run Code Online (Sandbox Code Playgroud)
不幸的是,这只是b''作为回应。虽然我已经使用了它,但我没有得到项目 ID
gcloud config set project my-project
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙,因为我是谷歌云和 python 的新手吗?谢谢。
这是下面的附加问题: 问题 2:
在我的本地系统中,我已经安装了 gcloud,如果我从那里运行上面的 python3.7 脚本
x=urllib.request.urlopen(url) #this line
Run Code Online (Sandbox Code Playgroud)
我从上面的行中收到此异常:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1240, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1286, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line …Run Code Online (Sandbox Code Playgroud) python python-requests google-api-python-client google-cloud-python
我正在尝试从 GCP 环境外部通过 Python 以编程方式访问受 IAP 保护的 App Engine Standard 应用程序。我尝试了各种方法,包括此处文档中显示的方法: https: //cloud.google.com/iap/docs/authentication-howto#iap-make-request-python。这是我的代码:
from google.auth.transport.requests import Request
from google.oauth2 import id_token
import requests
def make_iap_request(url, client_id, method='GET', **kwargs):
"""Makes a request to an application protected by Identity-Aware Proxy.
Args:
url: The Identity-Aware Proxy-protected URL to fetch.
client_id: The client ID used by Identity-Aware Proxy.
method: The request method to use
('GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE')
**kwargs: Any of the parameters defined for the request function:
https://github.com/requests/requests/blob/master/requests/api.py
If …Run Code Online (Sandbox Code Playgroud) google-app-engine google-api-python-client google-cloud-platform google-iap google-cloud-identity
你好,我正在尝试将 Google Sign In 集成到我的 python 脚本中,并且运行此错误:
\n访问被阻止:此应用程序\xe2\x80\x99s请求无效
\n您无法\xe2\x80\x99 登录,因为此应用发送了无效请求。您可以稍后再试,或者联系开发人员解决此问题。了解有关此错误的更多信息
\n如果您是此应用程序的开发人员,请参阅错误详细信息。
\n错误 400:redirect_uri_mismatch
\n我尝试运行的 python 脚本是来自 Google 来源的基本脚本:
\n# import the required libraries\nfrom googleapiclient.discovery import build\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom google.auth.transport.requests import Request\nimport pickle\nimport os.path\nimport base64\nimport email\nfrom bs4 import BeautifulSoup\n\n# Define the SCOPES. If modifying it, delete the token.pickle file.\nSCOPES = ['https://www.googleapis.com/auth/gmail.readonly']\n\ndef getEmails():\n # Variable creds will store the user access token.\n # If no valid token found, we will create one.\n …Run Code Online (Sandbox Code Playgroud) python oauth-2.0 google-api-python-client gmail-api google-developers-console
我正在尝试验证我的凭据以访问GMail API.以前我使用run()OAuth2中的方法和代码执行credentials = tools.run(flow, STORAGE, http=http)此操作,但现在这是一个不推荐使用的方法.我现在正在使用该run_flow()方法来验证我的凭据.
import httplib2
import argparse
from apiclient import errors
from apiclient.discovery import build
from oauth2client import tools
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
CLIENT_SECRET_FILE = 'your_client_secret.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.modify'
STORAGE = Storage('gmail.storage')
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
credentials = STORAGE.get()there are credentials, no reauth is needed
#parser = argparse.ArgumentParser(parents=[tools.argparser])
#flags = parser.parse_args() #Put your arguments in the parenthesis
if credentials is None or credentials.access_token_expired:
credentials …Run Code Online (Sandbox Code Playgroud) oauth-2.0 oauth2client google-oauth google-api-python-client gmail-api
python ×8
gmail-api ×3
google-api ×3
oauth-2.0 ×2
google-iap ×1
google-oauth ×1
oauth2client ×1
pyinstaller ×1
python-2.7 ×1
python-3.x ×1