B4J Question Google Play Developer In-App purchase server Data

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to get the Google Play Developer API working: https://www.b4x.com/android/forum/threads/google-play-developer-api.81839/#post-518277

In Google API Manager I have Google Play Android Developer API enabled etc.

Based on the example in the above thread, it looks like it's working and sending and receiving data etc.

So far so good..

The question I have is, when a user uses my app (B4A) and purchases the in-app purchase, what data needs to be sent to the GooglePlayDeveloperServer in order to check if that purchase was successful ?

I want to verify if the purchase was successful or not from my B4J server.

Looks like I need to use the following API in order to check the in app purchase: https://developers.google.com/android-publisher/api-ref/purchases/products/get


GET https://www.googleapis.com/androidp...ame/purchases/products/productId/tokens/token

From the test sub I have the following as the j.download:
https://www.googleapis.com/androidp...age.InAppPurchaseSKUHere/tokens/SomeTokenHere

Not sure where the token comes from? I guess this needs to be sent to the B4J app from the B4A app but not sure where to get it from, or it's some other token from somewhere else?

Problem I have when I run the above, I get:

Waiting for debugger to connect...
Program started.
Getting access token from refresh token...
{
"error": "unauthorized_client",
"error_description": "Unauthorized"
}
Error accessing account.

However, I was able to run the example from the tutorial so I know my ClientId & ClientSecret is correct.

Not sure on what I am doing wrong ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Can you post the relevant code?
See the PM I sent you.

In the GooglePlayDeveloperServer:
Inventory module:
B4X:
Sub Download (resp As ServletResponse)
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        Log("Error accessing account.")
        Return
    End If
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://www.googleapis.com/androidpublisher/v2/applications/my.package.name/purchases/products/my.package.name.in-app-sku-here/tokens/purchaseToken_from_B4A_when_the_in_app_purchase_was_made")
    j.GetRequest.SetHeader("Authorization", "Bearer " & Token)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        resp.Write(j.GetString)
    Else
        Log("Online data not available.")
    End If
    j.Release
    Log("Done!!!")
    StopMessageLoop
End Sub

GooglePlayDeveloper:
Main Module:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    DataFolder = File.DirData("GooglePlayDeveloper")
    oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/androidpublisher", _
        ClientSecret, DataFolder)
    Test("my.package.name")
End Sub

Sub Test (PackageName As String)
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        Log("Error accessing account.")
        Return
    End If
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://www.googleapis.com/androidpublisher/v2/applications/my.package.name/purchases/products/my.package.name.in-app-sku-here/tokens/purchaseToken_from_B4A_when_the_in_app_purchase_was_made")
 
 
 
    j.GetRequest.SetHeader("Authorization", "Bearer " & Token)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log("Online data not available.")
    End If
    j.Release
    Log("Done!!!")
    ExitApplication
End Sub
 
Last edited:
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Does it work? Do you see the list of products?

No, doesn't seem to work :(

Using GooglePlayDeveloperUI:

I replaced packageName with my App's package name.

When I run it, it logs the following in the IDE:

Waiting for debugger to connect...
Program started.
Getting access token from refresh token...
{
"error": "unauthorized_client",
"error_description": "Unauthorized"
}
Error accessing account.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top