0

次の URL でデータ視覚化のチュートリアルに取り組んでいます。

http://blog.blprnt.com/blog/blprnt/your-random-numbers-getting-started-with-processing-and-data-visualization

このエラーが発生していますが、何が原因なのか完全にわかりません。

com.google.gdata.util.AuthenticationException: ログイン URI との接続中にエラーが発生しました認証中にエラーが発生しました

これまでの私のコードは次のとおりです。

MyRandomNumbers ファイル

SimpleSpreadsheetManager sm;
String sUrl = "t6mq_WLV5c5uj6mUNSryBIA";
String googleUser = "xxxxxxx";
String googlePass = "xxxxxxx";

void setup() {
 size(800,800);
 background(0);
 smooth();

 //Ask for list of numbers
 int[] numbers = getNumbers();

 fill(255,40);
 noStroke();
 for(int i = 0; i < numbers.length; i++){
    ellipse(numbers[i] * 8, width/2, 8,8); 
 }

};

void draw() {
};

GoogleCode ファイル

//Function to get an Array of integers from a Google Spreadsheet
  int[] getNumbers() {
      println("Asking Google for numbers...");
      sm = new SimpleSpreadsheetManager();
      sm.init("RandomNumbers", googleUser, googlePass);
      sm.fetchSheetByKey(sUrl, 0);

      int n = sm.currentListEntries.size();
      int[] returnArray = new int[n];
      for (int i = 0; i < n; i++) {
         returnArray[i] = int(sm.getCellValue("Number", i));
      };
      println("Got " + n + " numbers.");
      return(returnArray);
  };

  //Function to generate a random list of integers
  int[] getRandomNumbers(int c) {

      int[] returnArray = new int[c];
      for (int i = 0; i < c; i++) {
         returnArray[i] = ceil(random(0,99));
      };
      return(returnArray);
  };

SimpleSpreadsheetManager

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() {

  };

  /*

  INIT FUNCTION
  Opens session, uses username & password for authentication

  */

  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(e + " ERROR IN AUTHENTICATION");
    };

  };

  /*

  FETCH SHEET BY KEY
  Gets a spreadsheet listfeed using the unique key - this is in the URL of the spreadsheet
  The retrieved sheet is both returned and set as the currentListFeed

  */

  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("https://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);
  };

  /*

  GET CELL VALUE
  Returns the value held in an individual sheet cell.

  */

  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){

    };

  };

};

何か案は?

4

1 に答える 1

0

エラー メッセージには、アプリが Google サービスにログインできないことが示されています。Google アカウントを持っていて、googleUser と googlePass で認証情報を提供する必要があります。

blprnt から例をダウンロードし、Google 資格情報をスケッチに入力したところ、動作しました。

于 2014-02-06T12:04:17.067 に答える