Search code examples
google-app-enginegoogle-cloud-datastorechannel-api

How to use datastore key as Channel API client id?


I do the following:

user = User()
...
user.put()
client_id = user.key() # value like agpkZXZ-Y3Njb3JlcgoLEgRVc2VyGAkM

token = channel.create_channel(client_id)

and I am getting InvalidChannelClientIdError.


Solution

  • client_id is a Key, create_channel(..) expects a string.

    Here is what docs say about InvalidChannelClientIdError:

    The specified Client ID is malformed. Client IDs must be UTF-8 or ASCII strings 
    and should be less than 64 characters.
    

    You could potentially use key.name() if your user id is generated by you and is sufficiently unique. If User id is generated by Datastore, then it is a short integer number like 1001, 2001, etc, and is not sufficiently unique.