Google云消息响应401,pushjack

时间:2015-05-07 12:47:28

标签: android python google-cloud-messaging

对于我的python服务器,我使用“pushjack”库向我的Android设备发送GCM推送通知。

在我的javascript客户端上,我使用Google Developers Consolde的概述页面上的项目编号作为我的senderID。当我点击屏幕时发送senderID并且我收到一个registrationID,然后使用XHR post将其发送到python服务器。然后,我使用凭据页面上提供的API密钥发送消息。

这是python服务器代码:

from pushjack import GCMClient, create_gcm_config

    config = create_gcm_config({
        'GCM_API_KEY': 'my_api_key'
    })

    client = GCMClient(config)

    registration_id = message ## Gotten from javascript client using XHR post

    data = {'param1': 'value1', 'param2': 'value2'}

    res = client.send(registration_id, data)

    print(res.responses)
    print(res.registration_ids)
    print(res.successes)
    print(res.failures)
    print(res.errors)
    print(res.canonical_ids)

我一直收到“[Response [401]]”并且在我的Android设备上没有收到任何通知。

我已将服务器的IP地址列入白名单,但我也尝试将服务器的IP从白名单中删除,但仍然收到401响应。

API的部分也启用了“Google Cloud Messaging for Android”。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

HTTP StatusCode 401表示您的API密钥无效。这是一个卷曲示例,用于检查您的API密钥是否有效。

# api_key=YOUR_API_KEY

# curl --header "Authorization: key=$api_key" \
       --header Content-Type:"application/json" \
       https://android.googleapis.com/gcm/send \
       -d "{\"registration_ids\":[\"ABC\"]}"

请参阅http://developer.android.com/google/gcm/http.html