Cenk YAGMUR
Cenk YAGMUR

Reputation: 3451

How can i use googleapis with flutter firebase

Im using flutter + firebase auth firestore etc. , i want use Purchases.products: get but explanation is not useful at all I did not understand how to auth

My Code

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}.');
    }

Upvotes: 1

Views: 653

Answers (1)

Cenk YAGMUR
Cenk YAGMUR

Reputation: 3451

Although there is no healthy document anywhere I found the experiment, I share it for those in need

You need to get 2 packages googleapis_auth and 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());
      });
    });

And you can creat keys like that

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.

Upvotes: 1

Related Questions