如何设置Google Cloud Platform并开始在Android应用中使用API?
问题描述:
设置Google云端平台。想要使用它的翻译API。在连接App的步骤上采样。 有一个IMG我的步骤,其中IM放养 如何设置Google Cloud Platform并开始在Android应用中使用API?
我已经在我的Windows 10
取得环境变量之后,有一段代码
// If you don't specify credentials when constructing the client, the
// client library will look for credentials in the environment.
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Bucket> buckets = storage.list();
for (Bucket bucket : buckets.iterateAll()) {
// do something with the info
}
但不明白是什么我应该这样做。我的下一步是什么?以及如何将Google Cloud API附加到我的应用。它与刚添加库类似吗?
有一个链接,引导https://cloud.google.com/docs/authentication/getting-started#auth-cloud-implicit-java
难道有人看到一步一步的在谷歌云平台指南权威性的Android?
答
有一个使用Firebase云端功能的教程,用于后端here。你只需要创建一个插入到实时数据库的Android客户端。
或者,如果您想直接从Android客户端调用URL API,你需要可以在https://console.cloud.google.com/apis/credentials
https://www.googleapis.com/language/translate/v2?key=${apiKey}&source=en&target=${lang}&q=${text}
获得用于调用Android的API URL API密钥,您可以使用Retrofit2
或FastAndroidNetworking
库。但它不会安全,因为您需要将您的api密钥放入客户端源代码
答
使用Translate API的最简单方法是使用HTTP请求发送。我认为你应该看到REST API的引用,以及你的API密钥的简单POST请求。