Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Problem connecting to google spreadsheet

$
0
0

I'm trying to connect to a google spreadsheet but am having problems with the authentication. I have read access to the spreadsheet but when I try connecting to it I get: ERROR IN AUTHENTICATION

This is my code: `//This is the Google spreadsheet manager and the id of the spreadsheet that we want to populate, along with our Google username & password SimpleSpreadsheetManager sm; String sUrl = "1iKKDYwIzByzdoAMLwIlqY5aRdTjNtykAcD39z0uMVGM"; String googleUser = "user"; String googlePass = "pass";

void setup() { size(800,800); sm = new SimpleSpreadsheetManager(); sm.init("RandomNumbers", googleUser, googlePass); sm.fetchSheetByKey(sUrl, 0);

}

void draw() {

} `

` import com.google.gdata.client.spreadsheet.*; import com.google.gdata.data.*; import com.google.gdata.data.spreadsheet.*; import com.google.gdata.util.*;

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map;

import java.util.Set;

public class SimpleSpreadsheetManager {

SpreadsheetService myService; SpreadsheetEntry spreadsheetEntry; SpreadsheetFeed sheetFeed; WorksheetEntry worksheetEntry;

List spreadsheets;

String user; String pass;

ListFeed currentListFeed; CellFeed currentCellFeed; List currentCells; List currentListEntries;

int currentTotalRows; int currentTotalCols;

String currentTitle; String[] tagArray;

URL listFeedUrl;

SimpleSpreadsheetManager() {

};

void init(String sessionName, String u, String p) { user = u; pass = p; myService = new SpreadsheetService(sessionName); try { myService.setUserCredentials(user, pass); } catch (Exception e) { println("ERROR IN AUTHENTICATION"); };

};

ListFeed fetchSheetByKey(String k, int wi) {

ListFeed f = new ListFeed();
CellFeed cf = new CellFeed();
WorksheetFeed w = new WorksheetFeed();

//GET WORKSHEETS FEED
try {
  URL worksheetFeedUrl = new URL("http://spreadsheets.google.com/feeds/worksheets/" + k + "/private/full");
  WorksheetFeed wf2 = new WorksheetFeed();
  w = myService.getFeed(worksheetFeedUrl, wf2.getClass());
}
catch(Exception e) {
  println("ERROR RETRIEVING WORKSHEET FEED");
};

List worksheets = w.getEntries();
WorksheetEntry we = (WorksheetEntry) worksheets.get(wi);   
println("RETRIEVED WORKSHEET " + we.getTitle().getPlainText()); 

//GET LIST FEED URL
try {
  listFeedUrl = we.getListFeedUrl();//new URL("http://spreadsheets.google.com/feeds/list/" + k + "/od6/private/full");
  ListFeed lf2 = new ListFeed();
  f = myService.getFeed(listFeedUrl, lf2.getClass());
}
catch(Exception e) {
  println("ERROR RETRIEVING LIST FEED");
};

//GET CELL FEED
try {
  URL cellFeedUrl = we.getCellFeedUrl();//new URL("http://spreadsheets.google.com/feeds/cells/" + k + "/od6/private/full");
  CellFeed lf2 = new CellFeed();
  cf = myService.getFeed(cellFeedUrl, lf2.getClass());

}
catch(Exception e) {
  println("ERROR RETRIEVING LIST FEED");
};

currentListFeed = f;
currentCellFeed = cf;
currentCells = cf.getEntries();
currentListEntries = f.getEntries();

currentTitle = we.getTitle().getPlainText();
currentTotalRows = currentListEntries.size();

if (currentListEntries.size() > 0) { ListEntry le = (ListEntry) currentListEntries.get(0);
currentTotalCols = le.getCustomElements().getTags().size();

Set<String> tags = le.getCustomElements().getTags();
tagArray = new String[tags.size()];
tagArray = tags.toArray(tagArray);

};

return(f);

};

String getCellValue(int c, int r) {

ListEntry le = (ListEntry) currentListEntries.get(r);    
Set<String> tags = le.getCustomElements().getTags();
String[] tagArray = new String[tags.size()];
tagArray = tags.toArray(tagArray);

return(le.getCustomElements().getValue(tagArray[c]));

};

String getCellValue(String tag, int r) {

ListEntry le = (ListEntry) currentListEntries.get(r);    
return(le.getCustomElements().getValue(tag));

};

void setCellValue(String tag, int r, String val) {

ListEntry le = (ListEntry) currentListEntries.get(r);    
le.getCustomElements().setValueLocal(tag, val);
try {
  ListEntry updatedRow = le.update();
}
catch (Exception e){

};

};

void setNewCellValue(String tag, int r, String val) {

ListEntry le = new ListEntry();  

try {
 le.getCustomElements().setValueLocal(tag, val);
 ListEntry insertedRow = myService.insert(listFeedUrl, le);
  ListEntry updatedRow = insertedRow.update();
}
catch (Exception e){

};

};

};`


Viewing all articles
Browse latest Browse all 2896

Trending Articles