标签: google-api-python-client

错误:“无法识别的参数:shell” - 适用于 Python 的 OAuth 2.0 Google API 客户端

我正在尝试进行纯粹的服务器端身份验证。我已遵循谷歌开发人员提供的代码示例中提到的所有过程。问题是execfile()在正常情况下工作正常python shell,但在python interactive shell.

以下是语句的日志。文件中还需要定义什么才能在Python Interactive Shellplaylistitems.py中执行。

代码playlistitems.py示例代码

Kshitij:trailers_backend Kshitij$ python manage.py shell
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> execfile("playlistitems.py")
usage: manage.py [--auth_host_name AUTH_HOST_NAME] [--noauth_local_webserver]
                 [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                 [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
manage.py: error: unrecognized arguments: shell
Kshitij:trailers_backend Kshitij$ 
Run Code Online (Sandbox Code Playgroud)

我通过更改本身的值来传递参数tools.py。以下是我收到的错误。我该如何解决?这个案例的端到端示例?

Traceback (most recent call …
Run Code Online (Sandbox Code Playgroud)

python shell oauth-2.0 google-oauth google-api-python-client

2
推荐指数
1
解决办法
3105
查看次数

Google API 读取 python 3 中的 .p12 密钥

UnicodeDecodeError我正在尝试将一些代码从 Python 2 移植到 3,但在读取 Google API .p12 服务密钥时抛出 a 。

with open('service_key.p12', 'r') as f:
    private_key = f.read()
Run Code Online (Sandbox Code Playgroud)

这是错误

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 1: invalid start byte

这段代码在 python 2.7 中工作正常,它在 python 3.4 中崩溃,我也已经pyOpenSSL==0.14安装了。

python encoding google-api google-api-python-client

2
推荐指数
1
解决办法
838
查看次数

oauth2client.client.ApplicationDefaultCredentialsError:应设置“type”、“authorized_user”或“service_account”值

我正在尝试从我的 Python 脚本访问 BigQuery API。目前我正在试验只是想让这个示例运行。

我创建了凭据,设置了环境变量并运行了脚本,却收到此错误:

oauth2client.client.ApplicationDefaultCredentialsError: An error was encountered while reading json file: /PATH/TO/MY/google_api_credentials.json (pointed to by GOOGLE_APPLICATION_CREDENTIALS environment variable): 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)
Run Code Online (Sandbox Code Playgroud)

嗯,它没有在 JSON 文件中设置:

{"installed":{"client_id":"blahblah.apps.googleusercontent.com","project_id":"blahblah","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"blahblah","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
Run Code Online (Sandbox Code Playgroud)

既然我从 Google 控制台下载了 JSON,它应该就可以工作吗?我不知道我需要定义什么“类型”。

python google-app-engine google-api google-oauth google-api-python-client

2
推荐指数
1
解决办法
3290
查看次数

权限不足错误 403:Google 云端硬盘上传 (Python)

我正在尝试使用 Drive API 版本 3 (Python) 访问 Google Drive。列出文件似乎工作正常。尝试上传文件时出现权限不足错误。

我更改了我的范围以授予我脚本的完全权限

SCOPES = 'https://www.googleapis.com/auth/drive'
Run Code Online (Sandbox Code Playgroud)

下面是我用来创建文件的块

file_metadata = {
    'name': 'Contents.pdf',
    'mimeType': 'application/vnd.google-apps.file'
}
media = MediaFileUpload('Contents.pdf',
                        mimetype='application/vnd.google-apps.file',
                        resumable=True)
file = service.files().create(body=file_metadata,
                                    media_body=media,
                                    fields='id').execute()
print ('File ID: %s' % file.get('id'))
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

ResumableUploadError: HttpError 403“权限不足”

我不确定这里有什么问题。

python google-drive-api google-api-python-client

2
推荐指数
1
解决办法
3804
查看次数

使用 Python 清空 Google Drive 垃圾箱

我试图用 API 清空我的谷歌驱动器垃圾箱,但没有运气。我曾尝试使用请求库,脚本运行没有错误,但驱动器垃圾没有被删除。我已经能够通过 API 获取文件,但不能删除或清空垃圾箱。似乎我应该能够只发送一个 http 请求,但这对我来说比看起来要困难得多。任何建议将不胜感激。这是我所拥有的。我什至没有收到 json 响应。

from __future__ import print_function
import httplib2
import os
import requests

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage


try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'C:\Scripts\Link Expiration\client_secret.json'
APPLICATION_NAME = 'Drive API Delete Trash'

def get_credentials():
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
    the …
Run Code Online (Sandbox Code Playgroud)

python google-api google-drive-api google-api-python-client

2
推荐指数
1
解决办法
2442
查看次数

使用 googleapiclient 请求库

以下是使用 httplib2 库访问谷歌存储桶的代码

import json
from httplib2 import Http
from oauth2client.client import SignedJwtAssertionCredentials
from googleapiclient.discovery import build
from pprint import pprint
client_email = 'my.iam.gserviceaccount.com'

json_file = 'services.json'


cloud_storage_bucket = 'my_bucket'

files = 'reviews/reviews_myapp_201603.csv'
private_key = json.loads(open(json_file).read())['private_key']

credentials = SignedJwtAssertionCredentials(client_email, 
private_key,'https://www.googleapis.com/auth/devstorage.read_only')
storage = build('storage', 'v1', http=credentials.authorize(Http()))
pprint(storage.objects().get(bucket=cloud_storage_bucket, object=files).execute())
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我是否可以使用 Python Requests 库发出 http 请求吗?如果是,如何?

python google-api oauth-2.0 python-requests google-api-python-client

2
推荐指数
1
解决办法
3398
查看次数

无法使用语音识别解决丢失的 google-api-python-client 模块

我正在尝试在安装了 Armbian 的 tinkerboard 上运行语音识别。我总是收到这个错误

ERROR - Error fetching results from Speech Recognition service missing google-api-python-client module: ensure that google-api-python-client is set up correctly.
Run Code Online (Sandbox Code Playgroud)

即使我使用 pip list 检查 pip 中已安装的软件包,我也可以看到 google-api-python-client 已安装。

pip 列表输出

cachetools (2.1.0)
certifi (2018.10.15)
chardet (3.0.4)
google-api-python-client (1.7.4)
google-auth (1.5.1)
google-auth-httplib2 (0.0.3)
httplib2 (0.11.3)
idna (2.7)
Mirage (0.9.5.2)
pip (9.0.1)
pyasn1 (0.4.4)
pyasn1-modules (0.2.2)
PyAudio (0.2.11)
pycairo (1.16.2)
requests (2.20.0)
rsa (4.0)
setuptools (40.4.3)
six (1.11.0)
SpeechRecognition (3.8.1)
uritemplate (3.0.0)
urllib3 (1.24)
wheel (0.32.2) …
Run Code Online (Sandbox Code Playgroud)

speech-recognition python-2.7 google-api-python-client google-cloud-speech armbian

2
推荐指数
1
解决办法
2683
查看次数

如何通过 python 客户端库启用 GCP API?

我正在尝试创建一个 python 函数来启用 GCP 项目所需的服务 API。我相信API调用将转到“serviceusage”API并使用“services.enable”或“services.batchEnable”方法。我不知道如何正确构建查询。

https://cloud.google.com/service-usage/docs/reference/rest/v1/services/enable

我已经能够使用 GCP Python 客户端库来自动化项目创建的大多数功能,但不能。我直接使用了 GCP 文档中的代码,但对于这种特定方法的信息很少

from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

project = 'projects/964030760997'  # TODO: Update placeholder value.

service = discovery.build('serviceusage', 'v1', credentials=credentials)
request = service.projects().services.list(project=project)
response = request.execute()


pprint(service)
Run Code Online (Sandbox Code Playgroud)

这是我得到的回应:

Traceback (most recent call last):
  File "enable_apis.py", line 29, in <module>
    request = service.services().services.list(project=project)
AttributeError: 'Resource' object has no attribute 'services'
Run Code Online (Sandbox Code Playgroud)

google-api-python-client google-cloud-platform

2
推荐指数
1
解决办法
2754
查看次数

使用python更新谷歌电子表格的单元格背景颜色

我想使用 google api 用batchupdate函数更新电子表格中单元格的背景颜色。 https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate 如果sheet1!A1用值value和背景颜色更新单元格,我的请求应该是什么样的red

python google-api-python-client google-sheets-api

2
推荐指数
1
解决办法
2343
查看次数

正确的 python 谷歌广告库?

负责编写与 Google Ad Manager 交互的客户端。据我所知,Google 发布了 PyPi 上的三个“官方”Python 客户端库。正如自述文件中所示,其中一个似乎是遗留的,但另外两个似乎正在积极开发。

https://github.com/googleapis/google-api-python-client (旧版,首次发布 = 2011 年)

https://github.com/googleads/googleads-python-lib (首次发布 = 2014 年)

https://github.com/googleads/google-ads-python (首次发布 = 2018 年)

后两者拥有相同的三位开发人员。使用哪个?

python google-ad-manager google-api-python-client google-ads-api

2
推荐指数
1
解决办法
491
查看次数