【问题标题】:How can i use googleapis with flutter firebase我如何将googleapis与flutter firebase一起使用
【发布时间】:2020-04-21 11:54:05
【问题描述】:

我正在使用flutter + 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}.');
    }

【问题讨论】:

    标签: firebase flutter oauth-2.0 google-api firebase-authentication


    【解决方案1】:

    虽然我在任何地方找到了这个实验都没有健康的文档,但我还是把它分享给有需要的人

    你需要得到2个包googleapis_authgoogleapis

    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.
    

    【讨论】:

      猜你喜欢
      • 2021-01-06
      • 2022-08-18
      • 2020-06-16
      • 2022-08-18
      • 2018-07-25
      • 2021-07-15
      • 2020-04-26
      • 2021-03-27
      • 2020-03-09
      相关资源
      最近更新 更多