def sendToPhone(self, data, email): #Get the registration entry info = Info.get_by_key_name(email) if not info: self.response.out.write('error_register') else: registration_id = info.registration_id #Get authentication token pre-stored on datastore with ID 1 #Alternatively, it's possible to store your authToken in a txt file and read from it (CTP implementation) info = Info.get_by_id(1) authToken = info.registration_id form_fields = { "registration_id": registration_id, "collapse_key": hash( email ), #collapse_key is an arbitrary string (implement as you want) } form_fields.update(data) form_data = urllib.urlencode(form_fields) url = "https://android.clients.google.com/c2dm/send" #Make a POST request to C2DM server result = urlfetch.fetch(url=url, payload=form_data, method=urlfetch.POST, headers={ 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'GoogleLogin auth=' + authToken }) if result.status_code == 200: self.response.out.write("OK") else: self.response.out.write("error_c2dm") logging.debug(result.status_code)
def sendToPhone(self,data,email): #Get the registration entry info = Info.get_by_key_name(email) if not info: self.response.out.write('error_register') else: registration_id = info.registration_id #Get authentication token pre-stored on datastore with ID 1 #Alternatively, it's possible to store your authToken in a txt file and read from it (CTP implementation) info = Info.get_by_id(1) authToken = info.registration_id form_fields = { "registration_id": registration_id, "collapse_key": hash(email), #collapse_key is an arbitrary string (implement as you want) } form_fields.update(data) form_data = urllib.urlencode(form_fields) url = "https://android.clients.google.com/c2dm/send" #Make a POST request to C2DM server result = urlfetch.fetch(url=url, payload=form_data, method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'GoogleLogin auth=' + authToken}) if result.status_code == 200: self.response.out.write("OK") else: self.response.out.write("error_c2dm") logging.debug(result.status_code)
def get(self): self.response.headers['Content-Type'] = 'text/plain' devregid = self.request.get('devregid') if not devregid: self.response.out.write('Must specify devregid') else: user = users.get_current_user() if user: #Remove entry with the associated email value info = Info.get_by_key_name(user.email()) info.delete() self.response.out.write('OK') else: self.response.out.write('Not authorized')
def get(self): self.response.headers['Content-Type'] = 'text/plain' devregid = self.request.get('devregid') if not devregid: self.response.out.write('Must specify devregid') else: user = users.get_current_user() if user: #Remove entry with the associated email value info = Info.get_by_key_name(user.email()) info.delete() self.response.out.write('OK') else: self.response.out.write('Not authorized')