相关疑难解决方法(0)

使用服务器密钥时,Google表格API会返回"来电者没有权限"

我在API Manager中生成了一个服务器密钥,并试图在我的Mac上执行以下操作:

curl 'https://sheets.googleapis.com/v4/spreadsheets/MySheetID?ranges=A1:B5&key=TheServerKeyIGeneratedInAPIManager'
Run Code Online (Sandbox Code Playgroud)

但这就是它的回报:

{
 "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "status": "PERMISSION_DENIED"
  }
}
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

google-api google-sheets google-sheets-api

47
推荐指数
5
解决办法
4万
查看次数

Google Cloud 授权在 Python 3 中持续失败 - 类型为 None,预期为 ('authorized_user', 'service_account') 之一

我第一次尝试从 Google 云存储下载文件。

我设置了从https://cloud.google.com/storage/docs/reference/libraries#client-libraries-usage-python下载的 googstruct.json 服务帐户密钥文件的路径

是否需要在代码之外设置对 Google Cloud 的授权?或者是否有比谷歌网站上更好的“如何使用谷歌云存储”?
看来我将错误的类型传递给storage_client = storage.Client() 异常字符串如下。

发生异常:google.auth.exceptions.DefaultCredentialsError 文件 C:\Users\Cary\Documents\Programming\Python\QGIS\GoogleCloud\googstruct.json 没有有效类型。类型为 None,应为 ('authorized_user', 'service_account') 之一。

我的 Python 3.7 代码

from google.cloud import storage
import os

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="C:\\GoogleCloud\\googstruct.json"

# Instantiates a client
storage_client = storage.Client()
bucket_name = 'structure_ssi'
destination_file_name = "C:\\Users\\18809_PIPEM.shp"
source_blob_name = '18809_PIPEM.shp'
download_blob(bucket_name, source_blob_name, destination_file_name)

def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(source_blob_name)

    blob.download_to_filename(destination_file_name)

    print('Blob {} downloaded to {}.'.format(
        source_blob_name, …
Run Code Online (Sandbox Code Playgroud)

google-cloud-storage google-oauth

7
推荐指数
1
解决办法
9340
查看次数

使用json keyfile从golang登录bigquery

所以我有一个如下所示的json密钥文件:

{
  "user_agent": null,
  "_scopes": "https://www.googleapis.com/auth/bigquery",
  "token_uri": "https://www.googleapis.com/oauth2/v4/token",
  "refresh_token": null,
  "_service_account_email": "...",
  "assertion_type": null,
  "_kwargs": {},
  "revoke_uri": "https://accounts.google.com/o/oauth2/revoke",
  "_private_key_pkcs8_pem": "-----BEGIN PRIVATE KEY----- ..."
  ...
}
Run Code Online (Sandbox Code Playgroud)

我想使用Golang将此文件登录到bigquery.我查看了https://github.com/GoogleCloudPlatform/google-cloud-go上的示例,但找不到任何与使用密钥文件创建新的bigquery客户端有关的内容.我错过了一些明显的东西吗

在python中,等价是:

        credentials = ServiceAccountCredentials.from_json_keyfile_name(
                'keyfile.json',
                'https://www.googleapis.com/auth/bigquery')

        ...
Run Code Online (Sandbox Code Playgroud)

go google-bigquery google-cloud-platform

6
推荐指数
1
解决办法
633
查看次数