简体   繁体   English

我的后端API名称是什么? 它在哪里? 从Android Studio客户端调用Google Cloud端点后端API

[英]What is my backend API name? Where is it? Calling Google Cloud endpoint backend API from Android Studio Client

I'd like to use google cloud endpoint v2 to connect to App Engine (and eventually google cloud sql (NOT firebase as I'll be making complex queries)) in my android studio (v3.3) project . 我想在我的android studio(v3.3)项目中使用Google Cloud Endpoint v2连接到App Engine(并最终连接到Google Cloud sql(因为我将进行复杂的查询,请不要使用Firebase))。

The google cloud SDK, OpenAPI, Endpoints configuration is working (it can receive an echo "hello world" through windows PowerShell) and I built the client libraries following this tutorial: https://cloud.google.com/endpoints/docs/frameworks/java/gen_clients Google Cloud SDK,OpenAPI,Endpoints配置正在运行(它可以通过Windows PowerShell接收回显“ hello world”),并且我按照本教程构建了客户端库: https : //cloud.google.com/endpoints/docs/frameworks / JAVA / gen_clients

I've imported my client libraries into the Android Studio project file Libs and am currently following this tutorial to call backend APIs from Android Studio Client: https://cloud.google.com/endpoints/docs/frameworks/java/calling-from-android 我已将客户端库导入Android Studio项目文件Libs,目前正在按照本教程从Android Studio Client调用后端API: https : //cloud.google.com/endpoints/docs/frameworks/java/calling-from -Android

After editing gradle files, it suggests replacing "Tictactoe" in the code below with the name of your backend API 编辑gradle文件后,建议使用您的后端API的名称替换下面代码中的“ Tictactoe”

Tictactoe.Builder builder = new Tictactoe.Builder(
    AndroidHttp.newCompatibleTransport(), new GsonFactory(), null);
service = builder.build();

I've spent 8 hours trying to figure what that would be. 我花了8个小时试图弄清楚那是什么。 I can't find any file in the imported libraries that works. 我在导入的库中找不到任何有效的文件。 I've tried using my Google Cloud project id on its own or followed by .appspot.com but nothing works. 我尝试单独使用我的Google Cloud项目ID,或者后面跟着.appspot.com,但没有任何效果。

I assume it must be somewhere in my Project File, I just need to know where. 我认为它必须在我的项目文件中的某个位置,我只需要知道位置。 And not knowing what it's called makes the search tricky. 而且不知道它的名字使搜索变得棘手。

Note: the Google Cloud site suggests asking technical questions on stackoverflow 注意:Google Cloud网站建议您就Stackoverflow提出技术问题

This name comes from several @Api annotations that are set when configuring the Endpoints API. 此名称来自配置Endpoints API时设置的几个@Api批注。 It sounds like you probably started off with the appengine-java8/endpoints-v2-backend example, which has the following declaration: 听起来您可能是从appengine-java8 / endpoints-v2-backend示例开始的,该示例具有以下声明:

@Api(
    name = "echo",
    version = "v1",
    namespace =
    @ApiNamespace(
        ownerDomain = "echo.example.com",
        ownerName = "echo.example.com",
        packagePath = ""
    ),
...

You can see the full definition in Echo.java . 您可以在Echo.java中看到完整的定义。

The important things to note here are both the name field, and the ownerDomain from the namespace . 这里要注意的重要事项是name字段和namespaceownerDomain Both of these together are used to generate the Java package that the code will belong in, but the segments of the ownerDomain path are reversed (as is standard in Java packages, which represent the hierarchy in the opposite way of normal DNS segments), so the Java package ends up being com.example.echo.echo . 这两个都用于生成代码将所属的Java包,但是ownerDomain路径的各段是相反的(如Java包中的标准,它以与正常DNS段相反的方式表示层次结构),因此Java包最终是com.example.echo.echo The Java class is just named after the @Api.name field (capitalized), so the class name is just Echo . Java类仅以@Api.name字段命名(大写),因此该类名为Echo

So, the fully qualified Java class you're looking for is: 因此,您要查找的标准Java类是:

com.example.echo.echo.Echo

or, for your exact code snippet: 或者,对于您的确切代码段:

com.example.echo.echo.Echo.Builder

This might be confusing because this example uses the word "echo" so many times, it's hard to attribute where each individual echo is coming from, but here's another example: 这可能会造成混淆,因为此示例使用了“ echo”一词很多次,很难归因于每个单独echo的来源,但这是另一个示例:

Let's say you set @Api.name to myApiName , and then set @Api.namespace.ownerDomain to mycompany.com . 假设您将@Api.name设置为myApiName ,然后将@Api.namespace.ownerDomain设置为mycompany.com The fully qualified Java class that you would use from the generated client library is: 您将从生成的客户端库中使用的标准Java类是:

com.mycompany.myApiName.MyApiName

However, I would not recommend that you try to manually figure out what the Java package and class name are based on these rules. 但是,我不建议您尝试根据这些规则手动确定Java包和类名。 The much easier thing to do is just look at the client library generated by Endpoints. 要做的更简单的事情就是查看由Endpoints生成的客户端库。

When you run gradle endpointsClientLibs , the command outputs the location of the file that it has generated as a .zip file. 当您运行gradle endpointsClientLibs ,命令会将其生成的文件的位置输出为.zip文件。 All you have to do is unzip this file and explore all of the generated code within it to easily see what the Java package structure looks like, and even the exact class definitions that Endpoints is generating for you. 您所需要做的就是解压缩该文件并浏览其中所有生成的代码,以轻松查看Java包结构的样子,甚至包括Endpoints为您生成的确切类定义。

If you're having trouble finding these classes in your IDE, I wonder if you might have accidentally missed steps 4-7 from the Generating a client library instructions: 如果您在IDE中找不到这些类时遇到麻烦,我想知道您是否可能意外地错过了生成客户端库指令中的步骤4-7:

4) Unzip the file using the unzip utility, or use another ZIP-compatible unarchiving utility:

unzip ./echo-v1-java.zip

5) Change directory: cd echo.

6) Build the client library:

gradle build

The output is in the `build/libs` directory. The exact filename depends on the version of the Java client. It is something like echo-v1-1.23.0-SNAPSHOT.jar.

7) Add the client library JAR to your Java or Android app.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于无状态后端应用程序的Google App Cloud Endpoint API - Google App Cloud Endpoint API for Stateless Backend App Google Cloud Module中的后端端点类未更新(Android) - Backend Endpoint Class in Google Cloud Module not Updating (Android) 如果后端是 URL,则从客户端到后端的 API 流 - API flow from Client to Backend in case backend is a URL Android Studio前端客户端[从设备运行]未连接到Google AppEngine后端 - Android Studio frontend client [running from Device] not connecting to Google AppEngine Backend 如何在Qt的android客户端代码中调用Google-Cloud-Messaging API? - How do i call the Google-Cloud-Messaging API in my android client code from Qt? Google Cloud Endpoint后端 - 是否可以检索HttpSession的属性? - Google Cloud Endpoint Backend - Is it possible to retrieve attributes of the HttpSession? Google Cloud Endpoint不在端点列表中创建Api - Google Cloud Endpoint Not Creating Api in Endpoint List 从我的 Spring Boot Rest API 返回的响应与提供给我的 rest API 的后端 API 不同 - Response returned from my Spring Boot Rest API is not same as the backend API provided to my rest API 在Android客户端上连接到Endpoint API - Connecting to Endpoint API on Android Client 带有JS Frontend和Java Backend的Google API - Google API with JS Frontend and Java Backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM