Java to Google Spreadsheet

前端 未结 5 1880
谎友^
谎友^ 2021-02-06 07:59

I was trying to do programming using Java to connect to Google Spreadsheet to do data retrieval or modifying data in the cells.

My Google spreadsheet link is https://doc

5条回答
  •  一个人的身影
    2021-02-06 08:38

    I was also getting the com.google.gdata.util.ParseException: Unrecognized content type:application/binary error, but I seem to have stumbled on a workaround for this strange bug. The code in Alex R's answer can be used as a starting point.

    1. First I tried changing the visibility to "public", just to see what would happen. Since the document is not published, I got the expected error response, containing:

      We're sorry. This document is not published.

    2. So I changed the visibility back to "private", and tried again just for fun...

      Lo, and behold; it worked!

    It works with either the Drive or Spreadsheets Feed scope (both can be included if you prefer):

    • https://www.googleapis.com/auth/drive
    • https://spreadsheets.google.com/feeds

    I'm not sure if its a factor, but I'm not using OAuth 2.0, but rather a Credential created from a PrivateKey (PKCS12 file), as in Brian Chapman's answer.

    Conclusion

    So, although it's kludgy, I've modified my application to always make a "public" request (wrapped in a try block to absorb the resulting Exception) just before making the "private" request. It's the only way I've been able to deterministically get the correct result.

提交回复
热议问题