0

I use Flask to run python backend server for Android application. I tried to send a message using Google gcm through HTTP and I got a result like this.

"{\"multicast_id\":856748271326331XXXX,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"MismatchSenderId\"}]}"

I was pretty sure that my API key and SENDER_ID matches with user information. I double checked SENDER_ID on Google developer console and it was same as what I put in Android application.

SENDER_ID - 32421541XXXX

Here is the python script that I used

import urllib2
import json

url = 'https://android.googleapis.com/gcm/send'
apiKey = 'XXXXXXXX2NWz5YKiWCqJYXYdbKO2QXXXXXXX' # my api key
myKey = "key=" + apiKey
regid = 'XXXXXXXXXo4wBhGqAIZGG0Ncx4Oll1Vz4eO_f9e0maGrEmM-bU-KY3BXDQhRZI54Xlh-B6m7G679uzAE0bM1MVTgOcJwpuF-hQm3Jfz4K8ROXwonaGmzg-XXXXXXXXXXXXXX'

# make header
headers = {'Content-Type': 'application/json', 'Authorization': myKey}

# make json data
data = {}
data['registration_ids'] = (regid,)
data['data'] = {'data':'i love changong'}
json_dump = json.dumps(data)
# print json.dumps(data, indent=4)

req = urllib2.Request(url, json_dump, headers)
result = urllib2.urlopen(req).read()
return json.dumps(result)

Do you see why I got this error? Thank you.

Jake
  • 1,195
  • 6
  • 21
  • 42

1 Answers1

1

I followed this answer and it worked. I should uninstall application and build application via eclipse again.

https://stackoverflow.com/a/13919215/2986636

Community
  • 1
  • 1
Jake
  • 1,195
  • 6
  • 21
  • 42