licensing verify problem...

A hint:

  1. Go to https://play.google.com/apps/publish;

  2. Enter Config on left pane;

  3. Developer Account > Account Details;

  4. Search for License Test;

  5. Enter the Gmail accounts that will test;

  6. Change the type of response that these accounts will get when the function License:verifyLicense() is called.

You can see these response if you insert the following line of code in License:licensing() function:

print(event.response)

Hi @Marcelrs,

Thank you very much for the information, I will be doing a test with this code.

Hi @Brent,

I believe you need to adjust the information that is on the “https://docs.coronalabs.com/api/library/licensing/” page so that other people do not have the same problem when using the sample code that is there.

Att.,

Joéver

Hi @Joéver,

What specifically would you like me to update in the docs?

Brent

Hi @Brent,

I believe that what @Joéver want to say is that the example code given at the https://docs.coronalabs.com/api/library/licensing/ is outdated.

When we compile the example of this page, it doesn’t work.

Marcel

Thanks guys, I’ll update the docs with a better example that matches the Corona sample Licensing project.

Brent

Hi @d.mach,

Can you show more of your code? I assume you followed all of the required steps to get licensing working?

Brent

if system.getInfo("platformName") == "Android" then     licensing = require "licensing"     provider = "google"     storeX = require("store")     -- Initializes the licensing module for this particular provider.     t = {}     function t:licensing( event )       --Prints the name of this event, "licensing".       response.text = (event.isError)       --Prints the name of the provider for this licensing instance, "google"       print(event.provider)       --Prints true if it has been verified else it prints false.       print(event.isVerified)       --Prints true if there was an error during verification else it will return nil.  Errors can be anything from configuration errors to network errors.       print(event.isError)       --Prints the type of error, "configuration" or "network".  If there was no error then this will return nil.       print(event.errorType)       --Prints a translated response from the licensing server.       print(event.response)       --Prints the expiration time of the expiration time of the cached license.       print(event.expiration)       local verifiedText = "NOT verified :("       if event.isVerified then         verifiedText = "Verified! :)"         -- important: we need a timer which is starting the game in case the licensing listener is NOT starting the game         -- important: we need a timer which is starting the game in case the licensing listener is NOT starting the game         if \_G.licenseStartTimer then             timer.cancel(\_G.licenseStartTimer)             \_G.licenseStartTimer=nil         end         timer.performWithDelay(200,startGameNow,1)       else         local onComplete=function(event)             -- Handler that gets notified when the alert closes             if ( event.action == "clicked" ) then                 -- leave game now                 --native.requestExit()-- not supported on iOS                 print ("Licensing ERROR!")                 if \_G.analyticsallowed==true then                     analytics.logEvent( "A Player started a PIRATED VERSION and now is getting to the Google Play Store!")                 end                 system.openURL( \_G.CC\_GameStoreLink )                 if \_G.licenseStartTimer then                     timer.cancel(\_G.licenseStartTimer)                     \_G.licenseStartTimer=nil                 end                 timer.performWithDelay(200,startGameNow,1)             end          end         -- quit the app here now because the app was NOT loaded via Google Play!         native.showAlert("Licensing ERROR!", "Info...",{ "YES" },onComplete)       end       response.text = verifiedText     end     if storeX.target == provider then        licensing.init( provider )     else         if \_G.licenseStartTimer then             timer.cancel(\_G.licenseStartTimer)             \_G.licenseStartTimer=nil         end         timer.performWithDelay(200,startGameNow,1)     end     -- If the target store isn't for this provider then the verify will not call the listener.     if storeX.target == provider then        licensing.verify(t)        response.text="verify"     else         if \_G.licenseStartTimer then             timer.cancel(\_G.licenseStartTimer)             \_G.licenseStartTimer=nil         end         timer.performWithDelay(200,startGameNow,1)     end end

I can get to the licensing.verify(t) but don’t get any feedback from the listener after that.

Am I seeing usage of iOS IAP (require “store”) in this Google-based implementation?

Yes… but this is working regarding the provider and storeX.target is giving back “google” here… so shouldn’t it call the listener then? I tried it with the google store implementation also with the same non-responding result.

And you did all of the other proper licensing setup in config.lua and so forth?

Yes. I have checked it more than once.
The only thing this game is doing differently is I’m using some “if’s” in config.lua to get the correct screen size, because it’s a pixel retro game. This is done like the following code (only showing a part of the config.lua to give the idea):

... if displayHeight\<=480 then &nbsp; application = { &nbsp;&nbsp;&nbsp;&nbsp; content = { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- correct one for portrait: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = math.floor(display.pixelWidth/(pix)), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height = math.floor(display.pixelHeight/(pix)), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --width = math.floor(display.pixelHeight/pix), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --height = math.floor(display.pixelWidth/pix), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --width = math.floor(320/pix), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --height = math.floor(480/pix), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --print ("aspectRatio is "..aspectRatio) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --width = 160 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --height = 240 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scale = "letterBox", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; antialiasing=true, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fps = 60, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; license = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; google = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; key = "CORRECT KEY HERE!!!", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --policy = "this is optional", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; policy = "serverManaged", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print ("license 1") elseif displayHeight\>480 and displayHeight\<=640 then &nbsp; application = { &nbsp;&nbsp;&nbsp;&nbsp; content = { ...

Am I seeing that you try to verify the license in the same block (runtime step) as you init it? That’s probably not advisable… I’d make 100% sure that it’s initialized before you try to verify.

Also, I suggest you use “system.getInfo( ‘targetAppStore’ )” instead of “store.target” to get the target app store you’re building for, in this case “google”.

https://docs.coronalabs.com/api/library/system/getInfo.html#targetappstore

Take care,

Brent

Thx for your help Brent. One question:

How can you make sure 100% that the init has worked before calling the verify?

Great question! The “licensing.init()” call will return true or false based on its success:

https://docs.coronalabs.com/api/library/licensing/init.html

Also make sure you added the CHECK_LICENSE permission for Android as noted on that page.

Take care,

Brent

Permission is already added.

When checking if the “licensing.init()” is true (or false)… does this mean I have to check (call) “licensing.init()” more than once?

With a timer maybe checking for true… like this:

timer.performWithDelay(1000,function() if licensing.init(“google”) then stopcheckandstartgame() end,0)

I suppose you could, but I’m not sure you’ll need to. If licensing dictates if the player can or can’t continue, then init() it and check for a “true” response. If it’s true, verify() the license, and if it succeeds, continue. Otherwise, you know something went wrong (bad license or some other issue in the licensing setup on Google’s side) and there’s probably no reason to continue.

One more thing:

Can this be tested with a previous .apk file version in the store, using another .apk with DEBUG build on device… or does the version be exact the same on device compared to the one in the store?

It looks like the init is not giving back true when I’m checking for it.

I’m not an expert on licensing, but I would imagine version numbers need to match. Google is likely very specific about these types of things. Hopefully somebody with time-tested expertise with Google licensing can chime in on this thread.

Dear,

I’m having the same problem. When I call the init () method it always returns false and looking in the debugg pops up a warning message saying it was rejected by google. The more interesting that I have an active product and the same opens perfectly for purchase, only validation of the license that does not work, I say this because the product buying part uses the same license code of the application and the version you are Using it must always be the same published in the google play store, that is to say, it is all just the licensing API. * That is not fucnionando.

Can you check if this API is working, can you test it? I’m talking about this because recently google made some changes to these license validations and I’m not sure if this could have affected the corona API.

Att.,

Joéver