Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android google平台服务身份验证上的JWT签名无效_Android_Oauth2_Service Accounts - Fatal编程技术网

Android google平台服务身份验证上的JWT签名无效

Android google平台服务身份验证上的JWT签名无效,android,oauth2,service-accounts,Android,Oauth2,Service Accounts,继续测试云语音API。。。 我从下载了另一个示例,并对其进行了轻微修改,因为类ClientAuthInterceptor已被弃用。我正在使用一个服务帐户,使用的相关代码如下: // This is contained in the MainActivity code. String fCred = _lu.getBasePath() + "auth.json"; try { InputStream isCred = new FileInputStream(fCred); Man

继续测试云语音API。。。 我从下载了另一个示例,并对其进行了轻微修改,因为类ClientAuthInterceptor已被弃用。我正在使用一个服务帐户,使用的相关代码如下:

// This is contained in the MainActivity code.
String fCred = _lu.getBasePath() + "auth.json";

try
{
    InputStream isCred = new FileInputStream(fCred);
    ManagedChannel channel = ManagedChannelBuilder.forAddress(HOSTNAME, PORT).build();
    mStreamingClient = new StreamingRecognizeClient(channel, isCred, RECORDER_SAMPLERATE);
}
catch (IOException openEx)
{
    Log.e(MainActivity.class.getSimpleName(), "Error", openEx);
}

// This is contained in the StreamingRecognizeClient class code
public StreamingRecognizeClient(ManagedChannel channel, InputStream credentials, int samplingRate) throws IOException
{
    this.mSamplingRate = samplingRate;
    this.mChannel = channel;
    GoogleCredentials creds = GoogleCredentials.fromStream(credentials);

    if (creds.createScopedRequired())
        creds = creds.createScoped(OAUTH2_SCOPES);

    CallCredentials callCreds = MoreCallCredentials.from(creds);
    mSpeechClient = SpeechGrpc.newStub(channel).withCallCredentials(callCreds);

    credentials.close();
}
所有这些代码都是在应用程序初始化期间调用的,文件auth.json是由Google控制台生成的身份验证文件,包含项目ID和私钥的所有信息。 然后,使用第一个音频数据块调用函数recognizeBytes;在发送实际音频数据之前,您必须仅发送带有识别配置的消息,这是通过以下功能完成的:

private void initializeRecognition() throws InterruptedException, IOException
{
    requestObserver = mSpeechClient.streamingRecognize(this);
    RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(AudioEncoding.FLAC).setSampleRate(mSamplingRate).build();
    StreamingRecognitionConfig streamingConfig = StreamingRecognitionConfig.newBuilder().setConfig(config).setInterimResults(true).setSingleUtterance(true).build();
    StreamingRecognizeRequest initial = StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingConfig).build();

    requestObserver.onNext(initial);
}
在第一次调用之后,我得到的是400错误代码,如下面的堆栈跟踪所述:

11-30 15:34:12.916 3676-7309/? W/StreamingRecognizeClient: recognize failed: {0}: Status{code=UNAUTHENTICATED, description=null, cause=java.io.IOException: Error getting access token for service account: }
11-30 15:34:12.918 3676-7309/? E/StreamingRecognizeClient: Error to Recognize.
   io.grpc.StatusRuntimeException: UNAUTHENTICATED
       at me.yurifariasg.StreamingRecognizeClient.onError(StreamingRecognizeClient.java:98)
       at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
       at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
       at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
   Caused by: java.io.IOException: Error getting access token for service account: 
       at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:227)
       at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:97)
       at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:74)
       at io.grpc.auth.GoogleAuthLibraryCallCredentials$1.run(GoogleAuthLibraryCallCredentials.java:113)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
       at java.lang.Thread.run(Thread.java:818) 
   Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
       {
           "error" : "invalid_grant",
           "error_description" : "Invalid JWT Signature."
       }
       at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
       at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:225)
                                                            ... 6 more
由于所有签署请求的过程都是由谷歌图书馆执行的,我不知道到底能做些什么。。。 我已经向谷歌技术支持发送了一个请求,在试用期内提供,但可能有人有一些建议

谢谢。
鲁道夫。

就我而言,我正在将符号文件上载到firebase崩溃报告。我在firebase控制台“生成新私钥”后,问题就解决了。那么,您是否尝试获取新的“auth.json”?

在我的例子中,我正在将符号文件上载到firebase崩溃报告。我在firebase控制台“生成新私钥”后,问题就解决了。那么,您是否尝试获取一个新的“auth.json”?

我的一个朋友(我为他发布了这个问题)终于创建了一个工作示例,它发送了一个预录制的flac音频文件。如果有人感兴趣,我会要求工作代码。这是Android Studio中的一个小项目。我的一个朋友(我为他发布了这个问题)终于创建了一个工作示例,它发送了一个预先录制的flac音频文件。如果有人感兴趣,我会要求工作代码。这是安卓工作室的一个小项目。