2017-02-26 10 views
0

私のウェブサイト/ localhostからGoogleアプリケーションスクリプトで自分の機能を実行するには本当に助けが必要です。ウェブサイト/ localhostからアプリスクリプト機能を実行

既にGoogleで検索しています。結果はgoogle.script.runである必要があります。私が試してみると、googleが機能していないというエラーが見つかりました。

これはアプリスクリプトの私の.gsコードINI:

/** 
* This script demonstrates the use of objDB using a spreadsheet as a database 
* 
* objDB is a Google Script Library that makes it easy to work with data stored in a spreadsheet. 
* Using the same functions, you can also work with data from a JDBC-connected database. 
* See http://googlescripts.harryonline.net/objdb for full documentation 
* 
* This demo uses the spreadsheet template from the tutorial on the Google Apps Script 
* https://developers.google.com/apps-script/storing_data_spreadsheets#reading 
* 
*/ 

/** 
* To restore the data from the original spreadsheet, run getSpreadsheet() 
* Try out the sample function, and create your own. 
* See the results in the log, as well as on the spreadheet itself 
* You can view the log file using View - Logs, or Alt-Enter 
* Alternatively, put breakpoints at the Logger.log statements and use Debug instead of Run 

/** 
* Create a copy of the tutorial spreadsheet and stores the ID of the newly created spreadsheet 
* in Usersettings, so you can continue using this. 
* Restore data from original tutorial spreadsheet 
*/ 

function getSpreadsheet() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName('Tutorial Data'); 
    sheet.clear(); 
    var tutorialID = '0Aq4s9w_HxMs7dFNtWlh2MHRWZzEtbk5LRW5hTVR1Y1E'; 
    var tutorialDataRange = SpreadsheetApp.openById(tutorialID).getSheets()[0].getDataRange(); 
    var range = sheet.getRange(1,1,tutorialDataRange.getNumRows(), tutorialDataRange.getNumColumns()); 
    range.setValues(tutorialDataRange.getValues()); 
} 

/** 
* Sample: get all data from Engineering employees 
*/ 

function getEngineers() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rows = objDB.getRows(ssDB, 'Tutorial Data', [], {Department:'Engineering'}); 
    Logger.log(rows); 
} 

/** 
* Sample: get John's phone number 
* Note that non-alphanumeric characters are stripped from column names: Phone Number becomes PhoneNumber 
*/ 

function getPhone() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rows = objDB.getRows(ssDB, 'Tutorial Data', ['PhoneNumber'], {FirstName:'John'}); 
    Logger.log(rows); 
} 

/** 
* Delete staff with id's 1342 and 1234 
*/ 

function deleteStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.deleteRow(ssDB, 'Tutorial Data', {EmployeeId:[1342,1234]}); 
    Logger.log(rowCount); 
} 

/** 
* Update: staff 3512 goes to marketing 
*/ 

function updateStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.updateRow(ssDB, 'Tutorial Data', {Department:'Marketing'}, {EmployeeId:3512}); 
    Logger.log(rowCount); 
} 

/** 
* Add new employee 
*/ 

function addStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.insertRow(ssDB, 'Tutorial Data', {FirstName:'Harry', LastName:'Potter', EmployeeId:4321, Department:'Magic',PhoneNumber:'(212) 123-4567'}); 
    Logger.log(rowCount); 
} 
+1

ページに他の.jsファイルを含めないでください。 – NDFA

+0

@BehradKhodayar私のウェブページにどのようなjavascriptファイルを含める必要がありますか? – DeVoresyah

+0

通常、文書にサードパーティライブラリを含めて – NDFA

答えて

1

を私は徹底的にGoogleのアプリケーションスクリプトを読んで。 App Scriptは基本的に、Google Apps(スプレッドシート、カレンダー、Gmail、ドキュメントなど)を拡張するためのサービスを開発者に提供するために構築されたもので、Design ByはGoogleクラウドサーバーから検索され実行される予定です。

GSスクリプトはサーバー側(Googleサーバー)で実行されるため、ウェブサイト/ローカルホストでは実行できません。

これを行うための推奨される方法は、is to make an htmlService app and use ajax from the frontendです。私はあなたの場合ではないと思います。

+0

別の方法があります。 [私の答え](http://stackoverflow.com/a/42474052/1595451) –

+0

@Rubénありがとうございますが、ここではAPIのバージョンを扱っていません(私の答えの最後に示唆したように)。彼は自分のホスト/ localhostに.gsファイルをアップロードしようとしていました。だから私は間違ったプロセスに注意を払った。 – NDFA

+0

ようこそ。それは私が他の手であなたと同じように質問を理解していないように見えます、あなたの提案は私と同じではありません:) –

0

外部のWebページまたはサービスからGoogle Appsスクリプトを実行するには、Google Apps Script Execution APIを使用してください。このリンクには、JavaScript、PHP、Pythonを含む広範な言語のいくつかの例が含まれています。