Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get email in users data in google play subscriptions an additional call to the Google Play Developer API. The subscription purchase #671

Open
PongPloy2016 opened this issue Jul 9, 2024 · 1 comment

Comments

@PongPloy2016
Copy link

PongPloy2016 commented Jul 9, 2024

hi How to get Email Playstore when use subscription an additional call to the Google Play Developer API. The subscription purchase

i have use get in code

` private suspend fun checkSubscription() {

    var  subscriptionPurchase = SubscriptionPurchase()
    try {
        val credential = subscriptionPurchase.getGoogleCredential(requireContext())
        val androidPublisher = subscriptionPurchase.getAndroidPublisher(credential)
        val subscriptionPurchase = subscriptionPurchase.getSubscriptionPurchase(androidPublisher, PACKAGE_NAME, SUBSCRIPTION_ID, PURCHASE_TOKEN)
        Log.d("SubscriptionChecker", "Subscription Status: ${subscriptionPurchase?.emailAddress}")

        // Check if email is present
        if (subscriptionPurchase?.emailAddress != null) {
            Log.d("SubscriptionChecker", "User Email: ${subscriptionPurchase.emailAddress}")
        } else {
            Log.d("SubscriptionChecker", "Email address not available for this purchase.")
        }
    } catch (e: Exception) {
        e.printStackTrace()
        Log.d("SubscriptionChecker Error", e.message.toString())

    }
} 


public fun getAndroidPublisher(credential: GoogleCredential): AndroidPublisher {
    return AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
       // .setApplicationName(APPLICATION_NAME)
        .build()
}

public suspend fun getSubscriptionPurchase(
    androidPublisher: AndroidPublisher,
    packageName: String,
    subscriptionId: String,
    token: String
): SubscriptionPurchase? {
    return withContext(Dispatchers.IO) {
        androidPublisher.purchases().subscriptions().get(packageName, subscriptionId, token).execute()
    }
}

public fun getGoogleCredential(context: Context): GoogleCredential {
val assetManager = context.assets
val inputStream: InputStream = assetManager!!.open(SERVICE_ACCOUNT_FILE_PATH)
return GoogleCredential.fromStream(inputStream)
.createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))
}`

and i. debug code in show detail. and why. not get email. please help

Screenshot 2567-07-01 at 13 32 52
@PongPloy2016 PongPloy2016 changed the title How to get email in playstore when user subscription an additional call to the Google Play Developer API. The subscription purchase How to get email in users data in google play subscriptions an additional call to the Google Play Developer API. The subscription purchase Jul 9, 2024
@matale
Copy link

matale commented Jul 17, 2024

You cant get email through the Google Play Developer API for most (practically all) users. If you look at the docs the emailAddress
The email address of the user when the subscription was purchased. Only present for purchases made with 'Subscribe with Google'.
Subscribe with Google was a very specific service that Google tried to introduce in 2018 that no one really uses anymore.
https://blog.google/outreach-initiatives/google-news-initiative/introducing-subscribe-google/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants