Android GCM send and MismatchSenderId

為{幸葍}努か 提交于 2019-12-20 05:13:08

问题


The odd thing is that notifications were working before. So I'm not sure what happened. I tried reinstalling my app to the device, but nothing changed.

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

Because this was working at one point, I know I am using the correct keys. I even triple checked based on other SOF threads I came across. What could be the potential problem now? I've looked around for a few days now and I'm still at a loss..

** EDIT **

Here's the POST info when a message is sent out from my server.

Headers

Array
(
    [0] => Authorization: key=xxxxxxx-key-for-browser-apps-from-google-apis-console-xxxxxxx
    [1] => Content-Type: application/json
)

Fields

Array
(
    [registration_ids] => Array
        (
            [0] => xxxxxxxxx-big-old-id-from-the-device-xxxxxxxx

    [data] => Array
        (
            [message] => hello
        )

)

Also

I am using the key associated with Key for browser apps (with referers).


回答1:


Apparently, when you recompile your app it will sometimes throw off the device id generation to where it won't match a previous id.

What I have to do is a COMPLETE uninstall of the app on my phone and recompile the app again (via eclipse). This seems quite pathetic, but it's the closest to a workable solution I have at the moment..




回答2:


I think it must be something to do with the way you have set up API access for your project in the Google APIs console, in particular the 'allowed referers'. As the dev docs say

Mismatched Sender A registration ID is tied to a certain group of senders. When an application registers for GCM usage, it must specify which senders are allowed to send messages. Make sure you're using one of those when trying to send messages to the device. If you switch to a different sender, the existing registration IDs won't work. Happens when error code is MismatchSenderId.

My project is set up to allow any referer like:

Key for browser apps (with referers) 
API key: my secret  
Referers: Any referer allowed

Perhaps you have restricted it to a certain IP range, and now you are trying to send the message from outside that range




回答3:


you did not use right device token, that's why you got the error. So, please get the new device token (Android mobile's token) and use it




回答4:


curl -X POST \
-H "Authorization: key= write here api_key" \
-H "Content-Type: application/json" \
-d '{"registration_ids": ["write here reg_id generated by gcm"],
"data": { "message": "Manual push notification from Rajkumar"}, "priority": "high" }' \ https://android.googleapis.com/gcm/send

MismatchSenderId because with in same device you have logged with different keys. to solve this problem uninstall app and run it againg and update the registration key. and then run the CURL script in your teminal which i post above it will give success message and you will get notification to your device



来源:https://stackoverflow.com/questions/13727585/android-gcm-send-and-mismatchsenderid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!