我正在使用gd_client.UpdateCell来更新谷歌电子表格中的值,我正在寻找一种方法来更新单元格的格式,即颜色,线条,文本化......
可以这样做吗?
有可用的示例或其他文档吗?
让我走的任何事都会很棒
python formatting google-spreadsheet-api google-api-python-client google-sheets-api
谷歌在这里有一个OAuth2客户端的例子
我完全是OAuth2的新手,我希望在我将OAuth2与我的应用程序集成之前让这个示例正常工作.我所做的是以下内容:
python moderator.py该应用程序打开一个浏览器,我可以(作为用户)授权应用程序访问我的帐户.但谷歌这样抱怨(400 Bad Request):
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:8080/ did not match a registered redirect URI
Learn more
Request Details
from_login=1
scope=https://www.googleapis.com/auth/moderator
response_type=code
access_type=offline
redirect_uri=http://localhost:8080/
approval_prompt=auto
as=-xxxxxxxxxxxxx
pli=1
client_id=xxxxxxxxxxx.apps.googleusercontent.com
authuser=0
hl=en
Run Code Online (Sandbox Code Playgroud)
我想localhost:8080来自一个由moderator.py启动的内部Web服务器.我的问题是:有人得到这个例子吗?我需要哪些其他组件(apache配置,DNS,...)
我对OAuth2非常困惑,任何帮助将不胜感激.
我想访问Google Calendar API以使用Python插入条目.我在Google API控制台上创建了一个服务帐户,添加了一个私钥,然后将其下载.
但是,当我尝试修改任何日历时,它在同一个帐户上,我收到以下错误消息.阅读作品.
代码是
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
event = {
'summary' : 'Appointment',
'location' : 'Somewhere',
'start' : {
'dateTime' : '2012-09-03T10:00:00.000-07:00'
},
'end' : {
'dateTime' : '2012-09-03T10:25:00.000-07:00'
}
}
f = file("key.p12", "rb")
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_name='423291807109-XXXXXXXXXXXXXXXXxx@developer.gserviceaccount.com',
private_key=key,
scope='https://www.googleapis.com/auth/calendar'
)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
request = service.events().insert(calendarId='XXXXXXXXXXXXXXXXXX@group.calendar.google.com', body=event)
response = request.execute()
print(response)
Run Code Online (Sandbox Code Playgroud)
错误信息是:
apiclient.errors.HttpError: <HttpError 403 …Run Code Online (Sandbox Code Playgroud) (为清楚起见,这篇文章与使用Python的Google App Engine上的Google Documents List API和Google Drive API之间的差异有关)
使用[现已弃用的]文档列表API,我能够通过导出为HTML,修改HTML然后重新上载来编辑Google文档,作为新文档或作为原始文档的修改.这对于从模板生成PDF文档等内容非常有用.我一直在尝试使用新的Drive API(V2)复制此功能,但似乎无法.
想出来了......
http = # authenticated http client
drive_service = build('drive', 'v2', http=http)
# get the file ...
file = drive_service.files().get(fileId=FILE_ID).execute()
# download the html ...
url = file['exportLinks']['text/html']
response, content = http.request(url)
# edit html
html = content.replace('foo', 'bar')
# create new file with modified html ...
body = {'title':'Modified Doc',
'description':'Some description',
'mimeType':'text/html'}
media_body = MediaIoBaseUpload(StringIO.StringIO(html), 'text/html', resumable=False)
drive_service.files().insert(body=body, media_body=media_body)
Run Code Online (Sandbox Code Playgroud)
上面的代码将html文件作为文件上传到Google云端硬盘,而不是将HTML呈现为Google文档.很公平,这是有道理的.但是我如何将其渲染为Google Doc,因为我可以使用Documents List API? …
python google-app-engine google-drive-api google-api-python-client
我可以 使用python为Google Drive 执行quickstart.py.但是我们如何存储令牌并再次使用它 - 再次针对同一用户而不提示用户.他们可以通过某种方式在Google驱动器上发送文件请求时使用访问令牌映射用户.
我们的GAE python应用程序使用Google Api Client for Python(目前我们使用版本1.3.1)与GAE特定的身份验证帮助程序与BigQuery进行通信.我们经常在与BigQuery通信时遇到套接字错误.
更具体地说,我们按如下方式构建了一个python Google API客户端
1. bq_scope = 'https://www.googleapis.com/auth/bigquery'
2. credentials = AppAssertionCredentials(scope=bq_scope)
3. http = credentials.authorize(httplib2.Http())
4. bq_service = build('bigquery', 'v2', http=http)
Run Code Online (Sandbox Code Playgroud)
然后,我们与BQ服务交互并获得以下错误
文件"/base/data/home/runtimes/python27/python27_dist/lib/python2.7/gae_override/httplib.py",第536行,在getresponse中'连接到服务器时出错:%s'%e)错误:连接到服务器时出错:无法获取URL:[api url ...]
引发的错误类型为google.appengine.api.remote_socket._remote_socket_error.error,而不是包装错误的异常.
最初我们认为它可能与超时有关,所以我们也尝试在上面的代码片段中设置超时更改第3行
3. http = credentials.authorize(httplib2.Http(timeout=60))
Run Code Online (Sandbox Code Playgroud)
但是,根据客户端库的日志输出,API调用不到1秒就会崩溃,显式设置超时并不会改变系统行为.
请注意,错误发生在各种API调用中,而不仅仅是单个API调用中,并且通常会在非常轻的操作中发生,例如,我们经常在轮询BQ以查找作业状态时看到错误,而很少在数据获取时看到错误.当我们重新运行操作时,系统工作.
知道为什么会发生这种情况并且 - 或许 - 这是处理它的最佳做法吗?
到目前为止,我可以将文件上传到该文件夹(如果存在).我不知道如何创建一个.因此,如果文件夹不存在,我的脚本就会死掉.
import sys
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gpath = '2015'
fname = 'Open Drive Replacements 06_01_2015.xls'
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
if file1['title'] == gpath:
id = file1['id']
file1 = drive.CreateFile({'title': fname, "parents": [{"kind": "drive#fileLink","id": id}]})
file1.SetContentFile(fname)
file1.Upload()
Run Code Online (Sandbox Code Playgroud)
你可以帮我修改上面的代码来创建文件夹gpath,如果它不存在吗?
在Google Developers Console上创建Google API Oauth2.0凭据时,我选择"Web应用程序"应用程序类型.
在"授权重定向URI"字段中,我可以使用http://127.0.0.1/callback,它可以在本地开发中正常使用.
但是当我想在我的服务器上使用Google API Oauth2.0 Credentials(比方说99.99.99.99)时,我必须使用http://99.99.99.99/callback作为我的"授权重定向URI",但Google会给我一个警告:
无效重定向:http://99.99.99.99/callback必须以公共顶级域名(例如.com或.org)结尾
除了将公共顶级域绑定到我的服务器之外,我还能做什么?
我在Django开发并使用oauth2client来处理Google API Oauth2,所以在我的数据库中有两个表"oauth2_authentication_credential","oauth2_authentication_flowmodel",其中包含凭据值,我将它们从我的localhost复制到服务器,但它没有'工作.
我对访问Youtube Analytics API以获取随机youtube频道存在问题.
使用以下范围成功授权后:
我保存token并refresh token在数据库中.一切都运作良好一段时间.在我的应用发出请求后一段时间(例如三个月),Google返回403:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
Run Code Online (Sandbox Code Playgroud)
但仅适用于Youtube Analytics API,Youtube Data API中的其他端点可以正常使用此令牌.这种情况发生在随机账户(渠道)上.此频道的所有者未撤消对我的应用的访问权限,未更改帐户密码等.
此问题影响我应用程序中所有渠道的大约40%(Youtube Analytics API停止工作的时间不同,从获取OAuth2令牌后的1到6个月).然后我必须定期向他们发送一个新的授权网址.
问题出在哪儿?
这是我生成一个auth url并发出请求的方式:
身份验证网址:
flow = client.flow_from_clientsecrets(
secret_file_path,
scope=["https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly"],
redirect_uri=redirect_url,
prompt="consent"
)
flow.params["access_type"] = "offline"
url = flow.step1_get_authorize_url(state=state)
Run Code Online (Sandbox Code Playgroud)统计要求:
auth = client.OAuth2Credentials.from_json(credentials_from_db)
http_auth = auth.authorize(httplib2.Http())
api = discovery.build("youtubeAnalytics", "v1", http=http_auth,
cache_discovery=False)
api.reports().query(
ids="channel==%s" % channel_id,
metrics="estimatedMinutesWatched",
dimensions="video",
start_date=start_date,
end_date=end_date, …Run Code Online (Sandbox Code Playgroud)python google-api youtube-api google-api-python-client youtube-analytics-api
我需要从 google 商务目录列表中获取联系人/电话列表。
我已经尝试过 Google 通讯录 api,它适用于“我的联系人”下的所有联系人,但不允许显示“目录”联系人。
我有什么用途/如何访问那些联系人(公司联系人)?
google-api google-contacts-api google-api-python-client google-admin-sdk
python ×6
google-api ×4
oauth-2.0 ×2
api ×1
calendar ×1
django ×1
formatting ×1
oauth ×1
pydrive ×1
youtube-api ×1