Gary is correct. I don't have access to my code at the moment but
that's the idea. It can be a bit confusing when you get started and
I've seen posts similar to this one, so maybe this will help a bit. I
do have a working solution (not yet public) that I've had running for
a couple of months now and it hasn't failed.
[Role Account]
*The Role account is the account you signed up with. This should be
something special that you use for this service. I would even login to
gmail once with it just to be sure everything's set before registering
with c2dm.
*Register your role account with C2DM (You've probably already done
this)
*Obtain the auth token (I used curl but the documentation outlines
other methods) for the role account. You will use this when sending
messages to the device using the role account. (role account + auth
token + registered device id + message)
[Application that you use to send the message to the device]
*The application sending the message (typically web app but really
could be anything) uses the role account to send a message to a device
and includes the auth token and the registered device id.
**The application sending the message should securely store the auth
token.
**The application sending the message should handle updates to the
auth token from Google in the response header when calling the c2dm
server. In theory, you can seed an auth token in your application
somehow (database, secure file, etc...) and your application updates
it when Google tells you to. This shouldn't require future
intervention.
[Device receiving message]
*Device registers with C2DM - Sends ROLE account. This is your role
account username that you're using for sending messages from the
server. You're basically telling Google... This device would like
messages from
c2dmrol...@gmail.com for this application; give me
an ID.
*Google returns a registered device ID (lfu98342u943248f3) and you
somehow send that to YOUR server [application sending the message].
Your server stores that so it knows how to get in contact with the
device. Every device should have a different ID.
Please don't use your role id as Google account on the phone. I
believe there's a bug related to this but I would consider it a poor
practice either way. If something happens to that account, you'll have
a headache on your hands down the road. Please create a new account
just for this and protect it... they're free after all.
Hope this helps.
-Mike