我遇到了很多例外,比如 NetworkMainthread。是的,我已按照https://developers.google.com/google-apps/spreadsheets/中的步骤进行操作
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String USERNAME = "xyz@gmail.com";
String PASSWORD = "rrrrrrr";
URL SPREADSHEET_FEED_URL = null;
try {
SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
/*https://spreadsheets.google.com/feeds/spreadsheets/public/full");*/
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
service.setProtocolVersion(SpreadsheetService.Versions.V3);
try {
service.setUserCredentials(USERNAME, PASSWORD);
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SpreadsheetFeed feed = null;
try {
feed = service.getFeed(SPREADSHEET_FEED_URL,SpreadsheetFeed.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
WorksheetFeed worksheetFeed = null;
try {
worksheetFeed = service.getFeed(
spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ServiceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = null;
try {
listFeed = service.getFeed(listFeedUrl, ListFeed.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<ListEntry> list = listFeed.getEntries();
for (ListEntry row : list) {
System.out.println(row.getTitle().getPlainText() + "\t" + row.getPlainTextContent());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}