标签: google-client

Google 商家资料 API readMask

在我的发现 url 被弃用后,我必须对我的代码进行一些更改,现在我收到此错误。

googleapiclient.errors.HttpError:<请求https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{*accountid*}/locations?filter=locationKey.placeId%3{*placeid*}&readMask=paths%3A+时出现 HttpError 400 %22locations%28name%29%22%0A&alt=json返回“请求包含无效参数。”。详细信息:“[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'read_mask', 'description': '提供的字段掩码无效'}] }]">

我正在尝试使用这个端点accounts.locations.list

我在用着 :

  • 蟒蛇3.8
  • 谷歌-api-python-客户端 2.29.0

我当前的代码如下所示:

from google.protobuf.field_mask_pb2 import FieldMask

googleAPI = GoogleAPI.auth_with_credentials(client_id=config.GMB_CLIENT_ID,
                                                client_secret=config.GMB_CLIENT_SECRET,
                                                client_refresh_token=config.GMB_REFRESH_TOKEN,
                                                api_name='mybusinessbusinessinformation',
                                                api_version='v1',
                                                discovery_service_url="https://mybusinessbusinessinformation.googleapis.com/$discovery/rest")

field_mask = FieldMask(paths=["locations(name)"])
outputLocation = googleAPI.service.accounts().locations().list(parent="accounts/{*id*}",
                                                                           filter="locationKey.placeId=" + google_place_id,
                                                                           readMask=field_mask
                                                                           ).execute()
Run Code Online (Sandbox Code Playgroud)

从错误中,我尝试了很多fieldmask路径,但仍然不知道他们想要什么。我尝试过诸如location.name、name、locations.name、locations.location.name 等操作,但没有成功。

我还尝试传递 readMask 参数,而不使用 FieldMask 类来传递字符串和相同的问题。

因此,如果有人知道他们想要的 readMask 的格式是什么,这对我来说会很棒!

可以帮助:

https://www.youtube.com/watch?v=T1FUDXRB7Ns

https://developers.google.com/google-ads/api/docs/client-libs/python/field-masks

python google-api google-client

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

gapi.auth2 无法获取 access_token

我正在尝试使用 javascript 客户端 API 为 youtube 实现可恢复的上传。我已经设法使用g-signin2按钮使登录正常工作,但我无法获取与请求一起发送的 access_token。这就是我呈现登录按钮的方式:

<span
  class="g-signin2"
  data-onsuccess="youtubeUploaderSigninCallback"
  data-scope="https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube">
</span>
Run Code Online (Sandbox Code Playgroud)

我正在使用从谷歌加载的以下脚本文件(如果没有另一个我似乎无法工作)

<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="https://apis.google.com/js/client.js" async defer></script>
Run Code Online (Sandbox Code Playgroud)

我正在使用来自https://developers.google.com/youtube/v3/code_samples/javascript#upload_video 的代码编辑示例来使用 XHR 进行可恢复的上传。但是这些示例使用此处标记为已弃用的身份验证函数:https : //developers.google.com/api-client-library/javascript/reference/referencedocs 所以我更改的主要内容是使用auth2andg-signin2而不是result.access_tokenand g-signin

所以我一直在尝试使用auth2函数来获取访问令牌,但是access_token当我执行以下代码时该属性未定义

gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse()
Run Code Online (Sandbox Code Playgroud)

我尝试获取访问令牌的方式记录在此处:https : //developers.google.com/api-client-library/javascript/features/cors#making-authenticated-requests

所以这些是我的选择,我想:

  1. 找到一种从用户对象中获取访问令牌的方法
    • (我发现 user.hg.access_token 包含我需要的令牌
    • 但“hg”对我来说似乎是一个缩小的财产
    • 所以我不打算使用它,因为它可能会随着更新而改变
    • 编辑:正如评论中指出的那样hg确实是一个缩小的财产,现在不再存在
  2. 将进度事件添加到 gapi.client.request()
    • 但 xhr 对象似乎没有暴露
  3. 使用记录为已弃用的代码

谁能帮我这个?几个小时以来,我一直在寻找可接受的解决方案,现在我想哭……孤单和绝望。

提前致谢,罗布

PS:我也在谷歌组上发布了这个问题

javascript google-client google-client-login

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

Youtube v3 Api 通过 ID 获取视频

如何ID使用Youtube API v3.

到目前为止,我只遇到过搜索机制和其他机制,但不是专门用于获取单个视频的机制,我目前拥有的代码是:

def youtube_search(q, max_results=1,order="relevance", token=None, location=None, location_radius=None):

   youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)

   search_response = youtube.search().list(
    q=q,
    type="video",
    pageToken=token,
    order = order,
    part="id,snippet",
    maxResults=max_results,
    location=location,
    locationRadius=location_radius

   ).execute()



  videos = []

  for search_result in search_response.get("items", []):
    if search_result["id"]["kind"] == "youtube#video":
        videos.append(search_result)
  try:
    nexttok = search_response["nextPageToken"]
    return(nexttok, videos)
  except Exception as e:
    nexttok = "last_page"
    return(nexttok, videos)
Run Code Online (Sandbox Code Playgroud)

但我发现这种方法效率不高,反而浪费时间和资源。我该怎么办呢?

youtube-api python-3.x google-client

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

Google Cloud Vision API-创建Grpc.Core.Channel时出错

我正在尝试使用Google Cloud Vision V1 Api的ImageAnnotatorClient类。我正在https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1/api/Google.Cloud.Vision.V1.ImageAnnotatorClient.html下的示例中

创建(ServiceEndpoint,ImageAnnotatorSettings)

标头。我正在使用C#并尝试构建经典的控制台应用程序。我正在使用来自Nuget的GRPC.Core版本1.15.0和Google.Cloud.Vision.V1版本1.2.0。我收到一个编译错误

“ GoogleCredential”不包含“ ToChannelCredentials”的定义,也找不到包含“ GoogleCredential”类型的第一个参数的扩展方法“ ToChannelCredentials”

下面是我的代码:

GoogleCredential credential = GoogleCredential
    .FromFile(@"C:\Users\...\12345.json")
    .CreateScoped(ImageAnnotatorClient.DefaultScopes);
            Google.Cloud.Vision.V1.Image image1 = Google.Cloud.Vision.V1.Image.FromFile(@"c:\Users\....\Image14b.png");

            Channel channel = new Channel(
    ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());
            ImageAnnotatorClient client = ImageAnnotatorClient.Create(channel);

            IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image1);
Run Code Online (Sandbox Code Playgroud)

我在下面的行出现错误:

        Channel channel = new Channel(
ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());
Run Code Online (Sandbox Code Playgroud)

有什么提示吗?

c# google-client google-cloud-platform google-cloud-vision

0
推荐指数
1
解决办法
258
查看次数