UrlFetchApp(Google Apps脚本)的参数错误无效

时间:2018-03-26 15:52:17

标签: google-apps-script urlfetch

我正试图从Google Apps脚本中的Amplitude Dashboard Rest API(documentation)中提取,但是我遇到了一个奇怪的错误。

以下是我想要的API调用:

Invalid argument: https://amplitude.com/api/2/funnels?e={"event_type":"_active"}&e={"event_type":"Purchase%20Confirmation%20Page%20-%20Page%20View%20-%20W"}&start=20180214&end=20180215&n=active&mode=ordered&cs=86400

以下是我的代码设置方式:

Here is the Java Script Code:

<html>
    <head>
        <title>Chat WebSocket</title>
        <script src="/gravity/resources/sockjs-0.3.4.js"></script>
        <script src="/gravity/resources/stomp.js"></script>
        <script type="text/javascript">
            var stompClient = null;

            function setConnected(connected) {
                document.getElementById('connect').disabled = connected;
                document.getElementById('disconnect').disabled = !connected;
                document.getElementById('conversationDiv').style.visibility 
                  = connected ? 'visible' : 'hidden';
                document.getElementById('response').innerHTML = '';
            }

            function connect() {
                var socket = new SockJS('/gravity/api/gravitywebsocket');
                stompClient = Stomp.over(socket);  
                stompClient.connect({}, function(frame) {
                    setConnected(true);
                    console.log('Connected: ' + frame);                 
                    stompClient.subscribe('/pos/asycnronous', function(messageOutput) {
                        var body = messageOutput.body; body.a=5;
                        showMessageOutput(body);
                                                                                                     });
                });                
            }

            function disconnect() {
                if(stompClient != null) {
                    stompClient.disconnect();
                }
                setConnected(false);
                console.log("Disconnected");
            }

            function sendMessage() {
                var from = document.getElementById('from').value;
                var text = document.getElementById('text').value;
                stompClient.send("/api/poschannel", {},JSON.stringify({'from':from, 'text':text}));
                                   }

            function showMessageOutput(messageOutput) {
                var response = document.getElementById('response');
                var p = document.createElement('p');
                p.style.wordWrap = 'break-word';
                p.appendChild(document.createTextNode(messageOutput.a + "***" +messageOutput.from + ": " 
                  + messageOutput.text + " (" + messageOutput.time + ")"));
                response.appendChild(p);
            }
        </script>
    </head>
    <body onload="disconnect()">
        <div>
            <div>
                <input type="text" id="from" placeholder="Choose a nickname"/>
            </div>
            <br />
            <div>
                <button id="connect" onclick="connect();">Connect</button>
                <button id="disconnect" disabled="disabled" onclick="disconnect();">
                    Disconnect
                </button>
            </div>
            <br />
            <div id="conversationDiv">
                <input type="text" id="text" placeholder="Write a message..."/>
                <button id="sendMessage" onclick="sendMessage();">Send</button>
                <p id="response"></p>
            </div>
        </div>

    </body>
</html>

我收到了错误:

public class ServerConnection {
    public enum ConnectionStatus {
        DISCONNECTED,
        CONNECTED
    }

    public interface ServerListener {
        void onNewMessage(String message);

        void onStatusChange(ConnectionStatus status);
    }

    private WebSocket mWebSocket;
    private OkHttpClient mClient;
    private String mServerUrl;
    private Handler mMessageHandler;
    private Handler mStatusHandler;
    private ServerListener mListener;

    public class SocketListener extends WebSocketListener {

        @Override
        public void onOpen(WebSocket webSocket, Response response) {
            super.onOpen(webSocket, response);

            try {
                System.out.println("On Open: Observe Response: " + response.body().string());
            } catch (Exception e) {
                Utility.stringify(e);
            }

            Message message = mMessageHandler.obtainMessage(Contract.ACTIVATE_POS_MESSAGE, ConnectionStatus.CONNECTED);
            mStatusHandler.sendMessage(message);
        }

        @Override
        public void onMessage(WebSocket webSocket, String text) {
            super.onMessage(webSocket, text);
            System.out.println("OnMessage: Observe result: " + text);
            Message message = mMessageHandler.obtainMessage(Contract.ACTIVATE_POS_MESSAGE, text);
            mMessageHandler.sendMessage(message);
        }

        @Override
        public void onMessage(WebSocket webSocket, ByteString bytes) {
            super.onMessage(webSocket, bytes.toString());
            System.out.println("OnMessage: Observe result: " + bytes.toString());
            Message message = mMessageHandler.obtainMessage(Contract.ACTIVATE_POS_MESSAGE, bytes.toString());
            mMessageHandler.sendMessage(message);
        }


        @Override
        public void onClosed(WebSocket webSocket, int code, String reason) {
            super.onClosed(webSocket, code, reason);
            System.out.println("OnClosed: Observe Reason: " + reason);
            Message message = mMessageHandler.obtainMessage(Contract.ACTIVATE_POS_MESSAGE, ConnectionStatus.DISCONNECTED);
            mMessageHandler.sendMessage(message);
        }

        @Override
        public void onFailure(WebSocket webSocket, Throwable t, Response response) {
            super.onFailure(webSocket, t, response);
            System.out.println("OnFailure: Observe Response: " + response);
            disconnect();
        }
    }

    public ServerConnection(String url) {
        mClient = new OkHttpClient.Builder()
                .readTimeout(5, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .build();

        mServerUrl = url;
    }

    public void connect(ServerListener listener) {
        Request request = new Request.Builder()
                .url(mServerUrl)
                .build();
        mWebSocket = mClient.newWebSocket(request, new SocketListener());
        mWebSocket.send("Hello, Testing Connection!");
        mListener = listener;
        mMessageHandler = new Handler(msg -> {
            mListener.onNewMessage((String) msg.obj);
            return true;
        });
        mStatusHandler = new Handler(msg -> {
            mListener.onStatusChange((ConnectionStatus) msg.obj);
            return true;
        });
    }

    public void disconnect() {
        mWebSocket.close(1000, "Completed");
        mListener = null;
        mMessageHandler.removeCallbacksAndMessages(null);
        mStatusHandler.removeCallbacksAndMessages(null);
    }

    public void sendMessage(String message) {
        mWebSocket.send(message);
    }
}

有人能帮助我理解我在这里做错了吗?提前谢谢!

0 个答案:

没有答案