我想在Google云端硬盘中创建一个空的Google表格(仅使用元数据创建).当我提到Google SpreadSheet API文档时,它说要使用DocumentsList API,但它已被弃用,而是要求我使用Google Drive API.在Drive API文档中,我找不到任何方法来创建空Sheet.任何人都知道如何做到这一点?
python google-drive-api google-api-python-client google-sheets-api
我们正在使用Python数据2.15库的开发人员python指南,并按照app引擎的说明.createSite("test site one",description ="test site one",source_site =(" https://sites.google.com/feeds/site/googleappsforus.com/google-site-template "))
每次使用时,我们都会收到无法预测的响应.
例外: HTTPException:等待来自URL的HTTP响应时超过截止日期:https://sites.google.com/feeds/site/googleappsforyou.com
有人遇到过同样的问题吗?AppEngine或Sites API是否相关?
问候,
我正在尝试让我的谷歌身份验证在请求 Gmail 和日历数据的 Django 应用程序上运行。我已经在 Google 开发者控制台中设置了 oAuth API 并将其与我的项目链接,并且我已经三次检查我的重定向 URI 是否与代码中的完全匹配(HTTP 与 HTTPS 没有错误,斜杠也没有任何不一致) )。我确保我的密钥、密钥、ClientID 和 Client Secret 在 Django 应用程序的管理页面中均已配置且相同。我已经遵循了许多 youtube 教程并搜索了有关堆栈溢出的其他问题,但身份验证仍然无法正常工作。我收到错误 400:redirect_uri_mismatch。尽管我已经检查了很多次以确认它们是相同的。
从所有教程中,我了解到此错误有两个主要根源:
这两个错误都有自己的个性化消息,说明不匹配的类型。
然而,我的却是这样说的:您无法登录此应用程序,因为它不符合 Google 的 OAuth 2.0 政策。\n\n如果您是应用开发者,请在 Google Cloud Console 中注册重定向 URI。
这是错误的照片 [![Google 身份验证错误消息][1]][1]
from django.shortcuts import render, redirect
from django.http import HttpRequest
from google_auth_oauthlib.flow import Flow
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from .models import CredentialsModel
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
import os
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = …Run Code Online (Sandbox Code Playgroud) python django google-authenticator google-oauth google-api-python-client
我编写了一个 Python 脚本(Google_add.py),用于在 Google Workspace 中创建用户。然而,当它运行时,发生了 AttributeError 。如何解决此错误?
\n\xe3\x83\xbbGoogle_add.py\xe3\x80\x80(摘录\xef\xbc\x89
\nPATH = \'/opt/Google/credentials.json\'\nCLIENT_SECRETS = \'/opt/Google/client_secrets.json\'\ncredentials = None\n\n#If there are credentials\nif os.path.exists(PATH):\n credentials = Credentials.from_authorized_user_file(\n path = PATH,\n scopes = SCOPES)\n\n#If there are no (valid) credentials available\nif not credentials or not credentials.valid:\n if credentials and credentials.expired and credentials.refresh_token:\n credentials.refresh(Request())\n else:\n FLOW = flow.InstalledAppFlow.from_client_secrets_file(\n client_secrets_file = CLIENT_SECRETS,\n scopes = SCOPES)\n credentials = FLOW.run_console()\n with open(PATH, \'w\') as token:\n token.write(credentials.to_json())\nRun Code Online (Sandbox Code Playgroud)\n\xe3\x83\xbb错误消息
\nFile "Google_add.py", line 186, in <module>\nmain()\nFile "Google_add.py", line 172, …Run Code Online (Sandbox Code Playgroud) google-oauth google-api-python-client google-admin-sdk google-workspace
如何使用Google Python客户端库以编程方式使用Google自定义搜索API搜索引擎进行高级搜索,以便n根据我查询的高级搜索的某些术语和参数返回第一个链接列表?
我试图检查文档(我没有找到任何例子),这个答案.但是,后者没有用,因为目前不支持AJAX API.到目前为止我试过这个:
from googleapiclient.discovery import build
import pprint
my_cse_id = "test"
def google_search(search_term, api_key, cse_id, **kwargs):
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
return res['items']
results = google_search('dogs', my_api_key, my_cse_id, num=10)
for result in results:
pprint.pprint(result)
Run Code Online (Sandbox Code Playgroud)
还有这个:
import pprint
from googleapiclient.discovery import build
def main():
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q='dogs').execute()
pprint.pprint(res)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
因此,任何关于如何使用谷歌的搜索引擎API进行高级搜索的想法?这就是我的凭据在Google控制台上的显示方式:
python google-api google-search-api python-3.x google-api-python-client
想尝试python,谷歌colaboratory 似乎是最简单的选择.我有一些文件在我的谷歌驱动器,并希望上传到谷歌colaboratory.所以这是我正在使用的代码:
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# 2. Create & upload a file text file.
uploaded = drive.CreateFile({'xyz.csv': 'C:/Users/abc/Google Drive/def/xyz.csv'})
uploaded.Upload()
print('Uploaded file with title {}'.format(uploaded.get('title')))
import pandas as pd
xyz = pd.read_csv('Untitled.csv')
Run Code Online (Sandbox Code Playgroud)
基本上,对于用户"abc",我想从文件夹"def"上传文件xyz.csv.我可以上传文件,但是当我要求标题时,标题是"无标题".当我要求上传的文件的ID时,它每次都会更改,因此我无法使用Id.
我怎么读文件??? 并设置一个正确的文件名???
xyz = pd.read_csv('Untitled.csv') doesnt work
xyz = pd.read_csv('Untitled') …Run Code Online (Sandbox Code Playgroud) python google-api google-drive-api google-api-python-client google-colaboratory
from pprint import pprint
from Goo_gle import Create_Service
CLIENT_SECRET_FILE = 'Client_Calendar.json'
API_NAME = 'calendar'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
Run Code Online (Sandbox Code Playgroud)
输出:
Traceback (most recent call last): File "d:\Play with code\PROGRAMMINGS\Python\Artificial Inteligence\calen_dar.py", line 2, in <module>
from Goo_gle import Create_Service File "d:\Play with code\PROGRAMMINGS\Python\Artificial Inteligence\Goo_gle.py", line 5, in <module>
from google_auth_oauthlib.flow import Flow, InstalledAppFlow File "C:\Python\lib\site-packages\google_auth_oauthlib\__init__.py", line 21, in <module>
from .interactive import get_user_credentials File "C:\Python\lib\site-packages\google_auth_oauthlib\interactive.py", line 27, in <module>
import google_auth_oauthlib.flow File "C:\Python\lib\site-packages\google_auth_oauthlib\flow.py", line …Run Code Online (Sandbox Code Playgroud) 徒劳无功地访问Google Admin SDK中的Directory API(参考).升级"google-api-python-client"软件包无法解决问题,因为"下载">"安装">"Python"链接指示.
我也没有在文档中看到它列出了API的程序化名称,所以我假设它是"目录",但也尝试过"directory.admin"和"admin.directory".我尝试运行测试代码时遇到以下异常:
apiclient.errors.UnknownApiNameOrVersion: name: directory version: v1
Run Code Online (Sandbox Code Playgroud)
有人可以协助我可能会忽略的东西吗?不幸的是,提供shell访问API的"快速入门"似乎被打破了(参考).当我选择Python>命令行>配置项目时,我收到一条错误,指出"抱歉,现在无法配置项目".
这是我在自定义目录库类中使用的相关代码段:
class Directory(object):
def __init__(self, httpConnection):
self.service = build('directory', 'v1', http=httpConnection)
Run Code Online (Sandbox Code Playgroud)
这只是一个没有客户端库可供API使用的情况吗?如果是的话,何时可以使用?
我一直在阅读有关如何更新用户自定义属性的文档.从如何编写,似乎我将能够做到以下几点:
email = "a@a.com"
results = service.users().list(domain="a.com",projection="full",query='email={0}'.format(email)).execute()
if len(results["users"]) == 1:
user = results["users"][0]
user["customSchemas"]["TEST"] = "TEST"
try:
userResponse = service.users().update(userKey=email, body=user).execute()
except HttpError, e:
print(e)
Run Code Online (Sandbox Code Playgroud)
但是,我抛出了错误:
https://www.googleapis.com/admin/directory/v1/users/test%40test.com?alt=json返回"未授权访问此资源/ api">
我不确定错误是因为我试图错误地更新字段,如果@url中的转义导致问题,或者我没有正确的范围(我正在使用https://www.googleapis.com/auth/admin.directory.user, https://www.googleapis.com/auth/admin.directory.domain, https://www.googleapis.com/auth/admin.directory.userschema).
如何为每个人创建自定义属性并使用python SDK为用户更新?
我正在按照此处的教程(https://cloud.google.com/ai-platform/training/docs/training-jobs#python_1)并使用Python将机器学习模型部署到Google云进行训练。但是,我收到 HttpError 403:“资源项目 my_project 的权限被拒绝。” 错误的原因是“CONSUMER_INVALID”。具体来说,返回的元数据显示使用者是“projects/my_project”,服务是“ml.googleapis.com”。
我去了AI平台,我的项目确实在那里。我请求使用的 API 已为该项目启用,并且环境变量 GOOGLE_APPLICATION_CREDENTIALS 已正确设置。我想知道如何解决这个问题。谢谢!
google-api-client google-api-python-client google-ai-platform