0

我最近一直在使用 opensocial,但在使用通知时遇到了麻烦。

我的代码是:

<?xml version="1.0" encoding="UTF-8"?>
<Module>
 <ModulePrefs title="Notifications" description="" height="300">
 <Require feature="opensocial-0.8"/>
</ModulePrefs>

<Content type="html">
<![CDATA[ 
    <script type="text/javascript">
        function sendNotification(title, body) {
            var params = {};
            params[opensocial.Message.Field.TITLE] = title;
            params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.NOTIFICATION;
            var message = opensocial.newMessage(body, params);
            var recipient = "VIEWER";
            opensocial.requestSendMessage(recipient, message, callback);
        };

        function callback(data) {
            if (data.hadError()) {
                alert("There was a problem:" + data.getErrorCode());
            } else {
                alert("Ok");
            }
        };
        sendNotification("This is a test notification", "How are you doing?");
    </script>
]]>
</Content>
</Module>

当我安装并运行这个小工具时,我没有收到任何警报或通知,我很困惑!

有任何想法吗?

4

1 回答 1

0

为了发送通知(例如 - 向朋友发送应用请求),我使用这个:

    var params = {};
    params[opensocial.Message.Field.TITLE] = response.response.title;
    var msg = opensocial.newMessage("Test request", params);
    opensocial.requestShareApp("VIEWER_FRIENDS", msg, function (data) { ... }

据我所知,OpenSocial 是谷歌产品,一些文档可以在 GoogleDocs 中找到。这里https://developers.google.com/orkut/docs/on-site-apps/people#viewer_owner描述了 VIEWER 和 OWNER。想想,你不应该使用 VIEWER 作为收件人。

于 2014-07-02T16:25:35.303 回答