首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对话框流API v2集成问题

对话框流API v2集成问题
EN

Stack Overflow用户
提问于 2018-12-29 14:23:00
回答 1查看 1.3K关注 0票数 4

我在安卓上使用对话框v1,但我想使用V2,因为它提供了更多的功能,因为V1将在2019年10月23日推出已弃用。但是,我不能将API V2集成到我的代码中。下面是V1代码:

代码语言:javascript
复制
private void initChatbot() {
    final AIConfiguration config = new AIConfiguration("Here put Client access token",
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);
    aiDataService = new AIDataService(this, config);
    customAIServiceContext = AIServiceContextBuilder.buildFromSessionId(uuid);// helps to create new session whenever app restarts
    aiRequest = new AIRequest();
}

下面是V2代码:

代码语言:javascript
复制
private void initV2Chatbot() {
    try {
        InputStream stream = getResources().openRawResource(R.raw.test_agent_credentials);
        GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
        String projectId = ((ServiceAccountCredentials)credentials).getProjectId();

        SessionsSettings.Builder settingsBuilder = SessionsSettings.newBuilder();
        SessionsSettings sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
        sessionsClient = SessionsClient.create(sessionsSettings);
        session = SessionName.of(projectId, uuid);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

当我为V2编写这段代码时,得到了以下错误:

代码语言:javascript
复制
error: cannot find symbol variable test_agent_credentials

实际上,我不知道什么是test_agent_credentials,也不知道为什么要使用它。有人能告诉我我应该把我的console.cloud.google对话框流İ集成密钥Id放在哪里吗?

这是等级:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    buildToolsVersion "28.0.3"
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.tyagiabhinav.dialogflowchat"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    repositories {
        mavenCentral()
    }


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // Java V2
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/INDEX.LIST'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.apis:google-api-services-oauth2:v1-rev145-1.25.0'


    // Dialogflow SDK dependencies
    implementation 'ai.api:sdk:2.0.7@aar'
    implementation 'ai.api:libai:1.6.12'

    // Java V2
    implementation 'com.google.cloud:google-cloud-dialogflow:0.67.0-alpha'
    // for Remote Procedure Call to avoid "No functional channel service provider found" error while creating SessionsClient
    implementation 'io.grpc:grpc-okhttp:1.15.1'
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-29 15:31:13

R.raw.test_agent_credentials引用假定位于原始资源文件夹中的test_agent_credentials.json文件。此JSON文件包含您在创建对话框集成服务帐户时下载的完整凭据文件。

忽略有关使用密钥的部分。它使用gloud命令生成在auth头中使用的键。你在用GoogleCredentials.fromStream()电话做这个。

重要的部分是在第10步之前,您保存JSON密钥文件并将其作为原始资源提供给Android。请参阅关于Android资源的这一信息,特别是关于原始资源的部分。原始资源应该放在名为" Raw“的子文件夹中的”资源“文件夹下。您在那里保存的文件的名称应该与R.raw后面没有"json“扩展名的部分资源名相匹配。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53970393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档