小编Kur*_*eek的帖子

如何在不将 client_secret.json 检查到版本控制的情况下使用 Google API?

我正在开发一个项目,根据https://12factor.net/config,我们不在代码中使用凭据之类的东西,而是在环境变量中使用。

我正在考虑使用 Google Sheets API 来整理数据库中的一些数据并将其放入 Google 表格中。这是来自https://developers.google.com/sheets/api/quickstart/python的部分示例脚本:

from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file as oauth_file, client, tools

# Setup the Sheets API
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
store = oauth_file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
Run Code Online (Sandbox Code Playgroud)

首先,从文档中我不清楚这个示例中应该包含什么'token.json'以及'credentials.json'应该是什么。从 API 控制台的“凭据”选项卡中,我下载了client_secret_<long suffix>.json如下所示的文件:

{"installed":{"client_id":"[our_client_id]","project_id":"nps-survey-1532981793379","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":"[our_client_secret]","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
Run Code Online (Sandbox Code Playgroud)

这个 JSON 文件应该是'token.json'本例中的 …

python google-api oauth2client google-oauth google-sheets-api

4
推荐指数
1
解决办法
7148
查看次数

将 google-auth 与 gspread 一起使用时,“'Credentials' 对象没有属性'access_token'”

我想使用gspread模块从 Python 编辑 Google 表格。的设置说明包含下面的例子:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('gspread-april-2cd … ba4.json', scope)

gc = gspread.authorize(credentials)
Run Code Online (Sandbox Code Playgroud)

但是,根据https://pypi.org/project/oauth2client/,该oauth2client库已被弃用。所以我尝试将其调整如下,使用google-auth:

import gspread
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file(
    'my_client_secrets.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/spreadsheets'])

gc = gspread.authorize(scoped_credentials)
Run Code Online (Sandbox Code Playgroud)

不幸的是,我遇到了以下错误:

(lucy-web-CVxkrCFK) bash-3.2$ python nps.py
Traceback (most recent call last):
  File "nps.py", line 54, in <module>
    gc = gspread.authorize(scoped_credentials)
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/gspread/__init__.py", line 38, in authorize
    client.login()
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/gspread/client.py", …
Run Code Online (Sandbox Code Playgroud)

python google-api google-authentication oauth2client

4
推荐指数
2
解决办法
9105
查看次数

使用节点检查时未定义预期变量?

我正在尝试使用该node inspect命令熟悉调试。我写use_debugger.js了一个简单的脚本,它定义了一个函数并调用它:

function count(nums, maxes) {
  debugger;
  return maxes;
}

count([1, 2, 3], [4, 5]);
Run Code Online (Sandbox Code Playgroud)

当我进入调试器时,我希望nums被定义并具有值[1, 2, 3]. 但是,如果我运行node inspect use_debugger.js然后在 REPL 中输入cand nums,我会发现它没有定义:

Kurts-MacBook-Pro:Scratch kurtpeek$ node --inspect-brk use_debugger.js
Debugger listening on ws://127.0.0.1:9229/7adfaada-c939-44a3-9150-6d1326b8c7d0
For help, see: https://nodejs.org/en/docs/inspector
^C
Kurts-MacBook-Pro:Scratch kurtpeek$ node inspect use_debugger.js
< Debugger listening on ws://127.0.0.1:9229/54fb6a12-82c8-4454-8307-6d120b0c26e8
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in use_debugger.js:1
> 1 (function (exports, require, module, …
Run Code Online (Sandbox Code Playgroud)

javascript debugging node.js

4
推荐指数
1
解决办法
661
查看次数

编译错误“错误:预期';' 在声明列表末尾”使用C ++中的Catch测试框架

我正在尝试通过在其中实现一些简单算法来学习C ++。为了测试这些算法,我想使用Catch2。这是我想进行二进制搜索的程序:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <iostream>
using namespace std;

int binary_search_recursive(int A[], int key, int low, int high) {
    if (low > high) {
        return -1;
    }
    int mid = (low + high)/2;
    if (A[mid] == key) {
        return mid;
    } else if (key < A[mid]) {
        return binary_search_recursive(A, key, low, mid-1);
    } else {
        return binary_search_recursive(A, key, mid+1, high);
    }
}

int binary_search(int A[], int key, int len) {
  return binary_search_recursive(A, key, 0, len - …
Run Code Online (Sandbox Code Playgroud)

c++ catch-unit-test

4
推荐指数
1
解决办法
1153
查看次数

即使在模拟器上,“adb root”命令也会返回“adbd 无法在生产版本中以 root 身份运行”?

我正在尝试adb root在模拟器上运行命令;这是我连接的唯一设备:

$ adb devices
List of devices attached
emulator-5554   device
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误消息:

$ adb root
adbd cannot run as root in production builds
Run Code Online (Sandbox Code Playgroud)

我试过按照这个答案,adb shell su 工作但 adb root 没有,以解决我的问题:

通过设计 adb root 命令仅适用于开发版本(即默认情况下具有 ro.debuggable=1 的 eng 和 userdebug)。或者,您可以使用修改后的 adbd 二进制文件(不检查 ro.debuggable)

但是,我不清楚如何将构建更改为开发构建而不是生产构建?

更新 我发现了一些额外的说明,这让我相信要使其工作,您需要使您的模拟器成为“可写系统”(参见如何在模拟器可写的 AVD 中制作系统分区)。但是,如果我尝试

$ emulator -avd Nexus_5X_API_28 -writable-system
emulator: WARNING: System image is writable
emulator: ERROR: Running multiple emulators with the same AVD is an experimental feature.
Please use -read-only …
Run Code Online (Sandbox Code Playgroud)

android adb

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

当没有定义 $GOPATH 时,如何找到使用“go get -u”安装的 Go 包?

我正在关注 Go 的 gRPC 快速入门教程,https: //grpc.io/docs/quickstart/go/,并使用命令安装了 gRPC

go get -u google.golang.org/grpc
Run Code Online (Sandbox Code Playgroud)

我实际上还没有定义GOPATH环境变量:

> echo $GOPATH
Run Code Online (Sandbox Code Playgroud)

据我了解,这意味着它默认为~/go,或者在我的情况下为/Users/kurt/go。

在下一步中,我想通过执行以下操作来构建示例

cd $GOPATH/src/google.golang.org/grpc/examples/helloworld
Run Code Online (Sandbox Code Playgroud)

但是,我发现该目录不存在,并且也没有google.golang.org目录/Users/kurt/go/src:

~/g/src> ls *google*
fish: No matches for wildcard '*google*'. See `help expand`.
ls *google*
   ^
Run Code Online (Sandbox Code Playgroud)

包裹不应该放在这里吗?这就是我从哪里得到安装包的理解?.

go gopath

4
推荐指数
1
解决办法
1679
查看次数

如何保持服务器处理在 Google Cloud VM 上运行?

这个问题似乎非常基本,但我无法在https://cloud.google.com/compute/docs/instances/create-start-instance快速找到答案。我正在 Google Cloud VM 上运行MicroMDM服务器,方法是使用 SSH 连接到(从 Google Cloud Console 中的 VM 实例页面),然后运行命令

> sudo micromdm serve
Run Code Online (Sandbox Code Playgroud)

但是,我注意到当我关闭笔记本电脑时,服务器也会停止,这实际上就是我首先想在虚拟机中运行服务器的原因。

保持服务器运行的推荐方法是什么?我应该使用systemd或运行该进程作为 Docker 容器吗?

virtual-machine google-cloud-platform server

4
推荐指数
1
解决办法
4025
查看次数

Google Pub/Sub 的 RetryPolicy 中配置的指数退避如何工作?

该cloud.google.com/go/pubsub库最近发布(在 v1.5.0 中,参见https://github.com/googleapis/google-cloud-go/releases/tag/pubsub%2Fv1.5.0)支持新的RetryPolicy服务器端功能。当前读取的文档(https://godoc.org/cloud.google.com/go/pubsub#RetryPolicy)

在此处输入图片说明

我读过维基百科文章,虽然它描述了离散时间的指数退避,但我没有看到这篇文章与MinimumBackoff和MaximumBackoff参数有什么具体关系。有关此指导下,我提到的文档github.com/cenkalti/backoff,https://pkg.go.dev/github.com/cenkalti/backoff/v4?tab=doc#ExponentialBackOff。该库将一个定义ExponentialBackoff为

type ExponentialBackOff struct {
    InitialInterval     time.Duration
    RandomizationFactor float64
    Multiplier          float64
    MaxInterval         time.Duration
    // After MaxElapsedTime the ExponentialBackOff returns Stop.
    // It never stops if MaxElapsedTime == 0.
    MaxElapsedTime time.Duration
    Stop           time.Duration
    Clock          Clock
    // contains filtered or unexported fields
}
Run Code Online (Sandbox Code Playgroud)

其中每个随机区间计算为

randomized interval =
    RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])
Run Code Online (Sandbox Code Playgroud)

哪里RetryInterval …

go publish-subscribe google-cloud-pubsub exponential-backoff

4
推荐指数
1
解决办法
1917
查看次数

正则表达式匹配带或不带前导零的小数

^([0-9]*[1-9][0-9]*(\.[0-9]+)?|[0]+\.[0-9]*[1-9][0-9]*)$
Run Code Online (Sandbox Code Playgroud)

我不太了解正则表达.上面的正则表达式不允许输入.2.但它允许所有其他小数,如0.2,0.02等.我需要让这个表达式允许数字如.2,.06等.....

regex

3
推荐指数
2
解决办法
8194
查看次数

资本化的"JPG"扩展不同于小写的"jpg"?

我正在制作个人网页,我已上传到www.kurtpeek.com的草稿版本.我注意到的一个错误是,我在"关于我"部分中的一个jpeg图像"MIT_IAP_SAR_smallest.JPG"没有显示在网络上,但是如果我在我的网站上查看它,我就能看到它电脑.(您可以从http://dl.dropbox.com/u/1396332/kurtpeek.com.rar下载该目录).

我可以看到与其他图片的唯一区别是,这个有一个大写的".JPG"扩展名而不是一个小写的".jpg".但是,如果我尝试将文件重命名为小写扩展名,则Windows 7会再次将其大写.

对此问题的任何帮助将不胜感激.

最诚挚的问候,Kurt Peek

PS这个问题看起来与此类似:

php文件上传大写文件名问题

但据我所知,问题没有解决.

html jpeg

3
推荐指数
1
解决办法
9368
查看次数