针对Chrome错误500的Google Cloud Messaging

So I'm trying to send a message to a chrome extension through GCM, using php.

$data = json_encode(array(
        'channelId' => 'channel id here',
        'subchannelId' => '0',
        'payload'=>'test'
    ));

    $ch = curl_init();
    $curlConfig = array(
        CURLOPT_URL            => "https://www.googleapis.com/gcm_for_chrome/v1/messages",
        CURLOPT_POST           => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_HTTPHEADER     => array(
            'Authorization: Bearer ' . $access_token,
            'Content-Type: application/json'
        )
    );
    curl_setopt_array($ch, $curlConfig);
    $result = curl_exec($ch);

Each request returns { "error": { "code": 500, "message": null } }. Thanks.

500 is the HTTP error code for internal error.

Sending a Google Cloud Message for Chrome from the Google oauthplayground website returns this for me:

HTTP/1.1 500 Internal Server Error Content-length: 52 X-xss-protection: 1; mode=block X-content-type-options: nosniff X-google-cache-control: remote-fetch -content-encoding: gzip Server: GSE Reason: Internal Server Error Via: HTTP/1.1 GWA Cache-control: private, max-age=0 Date: Wed, 15 May 2013 07:01:40 GMT X-frame-options: SAMEORIGIN Content-type: application/json; charset=UTF-8 Expires: Wed, 15 May 2013 07:01:40 GMT { "error": { "code": 500, "message": null } }

According to Google's Cloud Message for Chrome docs:

An internal error has occurred. This indicates something went wrong on the Google server side (for example, some backend not working or errors in the HTTP post such as a missing access token).

Essentially there's something wrong on Google's side of things. Considering Google I/O is going to start in a few hours I would assume they're currently making some changes.

Try checking again in a few hours.

I ran into the same problem today.

I found an issue tracker on the Chromium Apps group

https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-apps/UXE_ASCN0gc

One of the possible reasons for that is if the app you use for testing was never published in the Chrome Web Store. So if you created an app locally and load it into Chrome unpackaged for testing for example - it will always fail like this because GCM does not know who owns the app. When publishing the app to the Store, use the same google account that was used in Api Console to create a project and Oauth clientId/client secret etc. The GCM for Chrome works only if those google accounts match.

GCM verifies the owner of an app matches the owner of an access token to make sure nobody but owner of an app publishes messages for it. Publishing the app in the Web Store creates a link between a google account and the appID so it can be verified.

Now, once you publish some version of your app, you can add the magic token generated by Web Store to the manifest of your local app and continue modify/reload/debug locally, now having your app correctly registered for GCM. See my answer in chromium-apps group for more details on that.

I got the same error too. I resolved this by packaging my app and upload to chrome webstore. Then I use new Channel ID and it works now