问题
I'm trying to know if there are changes in my Dropbox. Basically this is my strategy (I'm using https://www.dropbox.com/developers-v1/core ):
- calling delta/last_cursor to get a cursor
calling long_poll_data with this cursor as parameter
/// I use RESTUtility and i've tried to adapt this code : http://www.programcreek.com/java-api-examples/index.php?api=com.dropbox.client2.RESTUtility /// example : 8 for last_cursor /// example : 13 for longpoll_delta /// https://www.dropbox.com/developers-v1/core/docs#delta // we use first the method : /delta/latest_cursor to get a cursor Log.d(" NotificationService", " ================================Finding latest cursor"); ArrayList<String> params = new ArrayList<>(); params.add("include_media_info"); params.add("false"); // if true there is a mistake Object response = RESTUtility.request(RESTUtility.RequestMethod.POST, "api.dropbox.com", "delta/latest_cursor", 1, params.toArray(new String[params.size()]), mDBApi.getSession()); /// Preparation of the cursor to use longpoll_ delta // response.toString() look like that : {"cursor":"AAGwyo3TijR4_dgBxCj8LrU-NBO5ET7xipVxMl_vGMn-O7PKemycTBR3FpK57856J-vTtn5wyNyzwJaaGlKn2h2o5gv8lBFzQ6Hn9KgdDHi7uH77boLG2Y1GOT1VgnWyxMU"} Log.d(" NotificationService", " ================================First cursor avant le substring : " + response.toString()); // lastestCursor look lije that : AAGwyo3TijR4_dgBxCj8LrU-NBO5ET7xipVxMl_vGMn-O7PKemycTBR3FpK57856J-vTtn5wyNyzwJaaGlKn2h2o5gv8lBFzQ6Hn9KgdDHi7uH77boLG2Y1GOT1VgnWyxMU latestCursor = response.toString().substring(11, response.toString().length() - 2); Log.d(" NotificationService", " ================================First cursor: " + latestCursor); //Try to use longpoll_delta to know if {"changes": false, "backoff": 60} changes is true ArrayList<String> paramsLongpoll_delta = new ArrayList<>(); paramsLongpoll_delta.add("cursor"); paramsLongpoll_delta.add(latestCursor); paramsLongpoll_delta.add("timeout"); paramsLongpoll_delta.add("120"); Object responseLongpoll_delta = RESTUtility.request(RESTUtility.RequestMethod.GET, "api-notify.dropbox.com", "longpoll_delta", 1, paramsLongpoll_delta.toArray(new String[paramsLongpoll_delta.size()]), mDBApi.getSession()); Log.d(" NotificationService", " ================================Second Cursor: " + responseLongpoll_delta.toString()); } catch (DropboxException e1) { e1.printStackTrace(); } } }); interrogateTheServerTask.start();
The point is: I get the response for the first call. But for the second I get this answer:
08-30 17:11:57.706 31971-32681/com.example.colombop.ble W/System.err: com.dropbox.client2.exception.DropboxIOException: java.net.SocketTimeoutException: Read timed out
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.dropbox.client2.RESTUtility.execute(Unknown Source)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.dropbox.client2.RESTUtility.execute(Unknown Source)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.dropbox.client2.RESTUtility.streamRequest(Unknown Source)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.dropbox.client2.RESTUtility.request(Unknown Source)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.example.colombop.ble.NotificationService$2.run(NotificationService.java:161)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at java.lang.Thread.run(Thread.java:818)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: Caused by: java.net.SocketTimeoutException: Read timed out
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:705)
08-30 17:11:57.707 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:108)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:196)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:88)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:179)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:185)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:240)
08-30 17:11:57.708 31971-32681/com.example.colombop.ble W/System.err: at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:264)
Does anybody has a suggestion?
来源:https://stackoverflow.com/questions/39231698/android-using-dropbox-api-to-know-if-there-are-changes-in-my-dropbox