1

これは本当に明白で簡単にできると確信していますが、その方法に関する情報が見つからないようです。

だから私は、JavaScriptを使用していくつかのことを行い、いくつかのデータを収集するChrome拡張機能を持っています。それはすべてうまくいきます。このデータを Google スプレッドシートに書き込みたい。そこで、Google スプレッドシート API を使用して、データを含む行を適切なスプレッドシートに挿入するコードを Java で記述しました。(コードは基本的に、ここにあるチュートリアルですhttps://developers.google.com/google-apps/spreadsheets/#adding_a_list_rowに適切な OAuth ビットを追加します)

拡張機能でこれを使用するにはどうすればよいですか? Web アプリとしてパッケージ化し、拡張機能から呼び出す必要がありますか? 同じことを実現する JavaScript コードを作成して、アプリにパッケージ化することはできますか? 繰り返しますが、これが本当に明白である場合は申し訳ありません。Web アプリケーションに取り組むのはこれが初めてなので、作業を進めながら理解しようとしています。ありがとう。

スプレッドシートに書き込むための (簡略化された) Java コードを次に示します。

public class MySpreadsheetIntegration {
      public static void main(String[] args)
          throws AuthenticationException, MalformedURLException, IOException, ServiceException {
           **OAuth stuff all happens first, not shown here as I'm not too concerned about it at the moment***

        SpreadsheetService service =
            new SpreadsheetService("MySpreadsheetIntegration-v1");

        // Define the URL to request.  This should never change.
        URL SPREADSHEET_FEED_URL = new URL(
            "https://docs.google.com/some_url");

        // Make a request to the API and get all spreadsheets.
        SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
            SpreadsheetFeed.class);
        List<SpreadsheetEntry> spreadsheets = feed.getEntries();

         //this pulls out the first spreadsheet.
        SpreadsheetEntry spreadsheet = spreadsheets.get(0); //spreadsheet is of type List
        //System.out.println(spreadsheet.getTitle().getPlainText());

        // Get the first worksheet of the first spreadsheet.
         WorksheetFeed worksheetFeed = service.getFeed(
            spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
        List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
        WorksheetEntry worksheet = worksheets.get(0);

        // Fetch the list feed of the worksheet.
        //I think this will give me the headings from the spreadsheet, but insert them manually for now
        URL listFeedUrl = worksheet.getListFeedUrl();
        ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

        // Create a local representation of the new row.
        ListEntry row = new ListEntry();
        String sDt, sUs, sTy, sAcc, sAccTy, sCon, sNt, sFw, sFwDt;

        sDt = "1/1/2013";
        sUs = "SK";

        row.getCustomElements().setValueLocal("Date", sDt);
        row.getCustomElements().setValueLocal("User", sUs);

        // Send the new row to the API for insertion.
        //this will be inserted at the bottom of the row. 
        //TODO make this get inserted at the top of the worksheet
        row = service.insert(listFeedUrl, row);

        System.out.println("Revoking OAuth Token...");
        oauthHelper.revokeToken(oauthParameters);
        System.out.println("OAuth Token revoked...");

      }
    }

拡張機能のポップアップは、フォームを含む基本的な HTML ページです。このフォームにいくつかの詳細を書き込むJavaScriptがあり、ユーザーは手動でさらに入力します。次に、スプ​​レッドシート API を使用してこれらの値を取得し、適切なスプレッドシートに書き込みます。これが上記の Java コードの機能ですが、この 2 つを接続する方法がわかりません。

4

0 に答える 0