Class StateTokenBuilder | Apps Script | Google for Developers (original) (raw)
StateTokenBuilder
อนุญาตให้สคริปต์สร้างโทเค็นสถานะที่ใช้ใน API การเรียกกลับได้ (เช่น ขั้นตอนการเรียก OAuth)
// Reusable function to generate a callback URL, assuming the script has been
// published as a web app (necessary to obtain the URL programmatically). If the
// script has not been published as a web app, set var url
in the first line
// to the URL of your script project (which cannot be obtained
// programmatically).
function getCallbackURL(callbackFunction) {
let url = ScriptApp.getService().getUrl(); // Ends in /exec (for a web app)
url = ${ url.slice(0, -4)}usercallback?state=
; // Change /exec to /usercallback
const stateToken = ScriptApp.newStateToken()
.withMethod(callbackFunction)
.withTimeout(120)
.createToken();
return url + stateToken;
}
เอกสารประกอบโดยละเอียด
createToken()
สร้างการนําเสนอสตริงที่เข้ารหัสของโทเค็นสถานะ
const stateToken = ScriptApp.newStateToken().createToken();
รีเทิร์น
String
— สตริงที่เข้ารหัสซึ่งแสดงโทเค็น
withArgument(name, value)
เพิ่มอาร์กิวเมนต์ลงในโทเค็น เรียกเมธอดนี้ได้หลายครั้ง
const stateToken = ScriptApp.newStateToken().withArgument('myField', 'myValue').createToken();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่ออาร์กิวเมนต์ |
value | String | ค่าของอาร์กิวเมนต์ |
รีเทิร์น
[StateTokenBuilder](#)
— ตัวสร้างโทเค็นสถานะสําหรับการต่อเชื่อม
withMethod(method)
ตั้งค่าฟังก์ชัน Callback ค่าเริ่มต้นคือฟังก์ชันชื่อ callback()
const stateToken = ScriptApp.newStateToken().withMethod('myCallback').createToken();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
method | String | ชื่อของฟังก์ชัน Callback ที่แสดงเป็นสตริงโดยไม่มีวงเล็บหรืออาร์กิวเมนต์ คุณสามารถใช้ฟังก์ชันจากไลบรารีที่รวมไว้ เช่น Library.libFunction1 |
รีเทิร์น
[StateTokenBuilder](#)
— ตัวสร้างโทเค็นสถานะสําหรับการต่อเชื่อม
withTimeout(seconds)
ตั้งค่าระยะเวลา (เป็นวินาที) ที่โทเค็นใช้งานได้ ค่าเริ่มต้นคือ 60 วินาที และระยะเวลาสูงสุดคือ 3,600 วินาที (1 ชั่วโมง)
const stateToken = ScriptApp.newStateToken().withTimeout(60).createToken();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
seconds | Integer | ระยะเวลาที่โทเค็นใช้งานได้ โดยค่าสูงสุดคือ 3600 |
รีเทิร์น
[StateTokenBuilder](#)
— ตัวสร้างโทเค็นสถานะสําหรับการต่อเชื่อม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-12-22 UTC