firebase - 我如何将googleapis与flutter firebase一起使用
问题描述
我正在使用颤振 + firebase auth firestore 等,我想使用Purchases.products: get但解释一点用都没有 我不明白如何进行身份验证
我的代码
var url = 'https://www.googleapis.com/auth/androidpublisher/v3/applications/'
'${purchaseDetails.billingClientPurchase.packageName}/purchases/products/'
'${purchaseDetails.productID}/tokens/'
'${purchaseDetails.billingClientPurchase.purchaseToken}';
var response = await http.get(url);
if (response.statusCode == 200) {
var jsonResponse = jsonDecode(response.body);
print(jsonDecode);
} else {
print('Request failed with status: ${response.statusCode}.');
}
解决方案
虽然在我找到实验的任何地方都没有健康的文档,但我将它分享给有需要的人
您需要获得 2 个包googleapis_auth和googleapis
import 'package:googleapis/androidpublisher/v3.dart' as androidPublisher;
import 'package:googleapis_auth/auth_io.dart' as auth;
final _credentials = new auth.ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": ...,
"private_key": ...,
"client_email": ...,
"client_id": ...,
"type": "service_account"
}
''');
const _SCOPES = const [
androidPublisher.AndroidpublisherApi.AndroidpublisherScope
];
auth.clientViaServiceAccount(_credentials, _SCOPES).then((httpClient) {
var publisher = new androidPublisher.AndroidpublisherApi(httpClient);
publisher.purchases.products
.get(
packageName,
productID,
purchaseToken)
.then((pub) {
debugPrint(pub.toJson().toString());
});
});
你可以创建这样的键
Open the IAM & Admin page in the Cloud Console.
Open the IAM & Admin page
Click Select a project, choose a project, and click Open.
In the left nav, click Service accounts.
Find the row of the service account that you want to create a key for. In that row, click the More more_vert button, and then click Create key.
Select a Key type and click Create.
推荐阅读
- c++ - 使用优化标志计算简单有限差分时的 clang++ v6、7 和 8 错误/错误结果
- java - 在 Java 中的正面和负面情况下如何发生类型扩展?
- node.js - 节点和MongoDB之间的连接
- ios - 按下取消按钮时隐藏搜索栏,并调整导航栏的大小
- python - 没有找到模块'corsheaders' django/heroku deploy
- mysql - MySQL 5.7.22:当键包含点字符时如何选择 JSON 值?
- python - 在 Python 中退出时如何捕获信号并传递变量?
- c++ - 学校项目的 if/else 语句
- batch-file - 如何在没有管理员权限的情况下自动化命令行 taskkill?
- laravel - 将数据从值返回到对象 Vuejs - Laravel