首页 > 解决方案 > Google Crendentials 为 NULL,我无法设置环境变量

问题描述

我正在尝试使用 ASP.Net 翻译文本框文本。在集成 Google 翻译 API 时,我进入了 TranslationClient.Create()。并且在元数据文件中,翻译客户端为空。即使我在环境变量中设置了凭据路径,但它仍然为空..如何解决它?

 TranslationClient Client = TranslationClient.Create();
    var text = txtCategoryName.Text;
    var resp = Client.TranslateText(text, LanguageCodes.English, LanguageCodes.ChineseSimplified);

*Meta DATA file*
public static TranslationClient Create(GoogleCredential credential = null, TranslationModel model = TranslationModel.ServiceDefault);
    //
    // Summary:
    //     Asynchronously creates a Google.Cloud.Translation.V2.TranslationClient, using
    //     application default credentials if no credentials are specified.
    //
    // Parameters:
    //   credential:
    //     Optional Google.Apis.Auth.OAuth2.GoogleCredential.
    //
    //   model:
    //     The default translation model to use. Defaults to Google.Cloud.Translation.V2.TranslationModel.ServiceDefault.
    //
    // Returns:
    //     The task representing the created Google.Cloud.Translation.V2.TranslationClient.
    //
    // Remarks:
    //     The credentials are scoped as necessary.
    [AsyncStateMachine(typeof(<CreateAsync>d__19))]
    public static Task<TranslationClient> CreateAsync(GoogleCredential credential = null, TranslationModel model = TranslationModel.ServiceDefault);

翻译客户端中的实际结果为空,而不是翻译文本

此图像中突出显示的行显示为空

元数据文件图像

标签: google-translate

解决方案


推荐阅读