在C#中找不到用于Google API身份验证的toChannelCredentials()

时间:2018-07-25 18:44:00

标签: c# authentication google-authentication google-vision

此页面https://cloud.google.com/docs/authentication/production上有一个指南,其中包含有关如何设置google API身份验证的示例。但是,我的IDE似乎无法理解或无法找到验证所需的“ ToChannelCredentials()”方法。有没有我未导入的特定内容?这是我的代码

using System;
using System.IO;
using Grpc.Core;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;
namespace ClassLibrary1
{
    public class Class1
    {
        public static void Main(String[] args)
        {
            var credential = GoogleCredential.FromFile("myPath").CreateScoped(ImageAnnotatorClient.DefaultScopes);
            var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.;
            var client = ImageAnnotatorClient.Create();
            var image = Image.FromFile("myImage");
            var response = client.DetectLabels(image);
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine(annotation.Description);
                }

            }
        }

    }
}

1 个答案:

答案 0 :(得分:1)

添加:

使用Grpc.Auth;

您将需要引用Google.Apis.Core。