Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Channel API sending message with token
    primarykey
    data
    text
    <p>In documents it says 'client_id' part can actually be the token, however it doesn't work. Anyone know why?</p> <p><a href="https://developers.google.com/appengine/docs/python/channel/functions" rel="nofollow">https://developers.google.com/appengine/docs/python/channel/functions</a></p> <blockquote> <p>If the client_id parameter is actually a token returned by a create_channel call then send_message can be used for different versions of the app. For instance you could create the channel on the front end and then send messages from a backend of the app.</p> </blockquote> <p>the reason i want to use this, is because i want to send messages to anonymous users as well, without requiring them to login. i don't know if it is possible to assign them a 'client_id' if token doesn't work.</p> <p>this is how i am creating the token</p> <pre><code> user = users.get_current_user() if user: token = channel.create_channel(user.user_id()) else: token = channel.create_channel(str(uuid.uuid4())) </code></pre> <p>then injecting into client</p> <pre><code>template_values = { 'token' : token, } </code></pre> <p>on the client side open the channel</p> <pre><code> openChannel = function() { var token = '{{ token }}'; var channel = new goog.appengine.Channel(token); var handler = { 'onopen': onOpened, 'onmessage': onMessage, 'onerror': function() {}, 'onclose': function() {} }; var socket = channel.open(handler); socket.onopen = onOpened; socket.onmessage = onMessage; } </code></pre> <p>now send a message</p> <pre><code>var xhr = new XMLHttpRequest(); xhr.open('POST', path, true); xhr.send(); </code></pre> <p>in the server, when the message is received send back a message using the token </p> <pre><code>channel.send_message(token, someMessage) </code></pre> <p>back to client</p> <pre><code>onMessage = function(m) { alert("you have some message"); } </code></pre> <p>this sequence works fine if client_id() is used instead of token when calling send_message</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload