Class LinkPreview
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
連結預覽資訊卡動作,可在主機應用程式中顯示連結預覽資訊卡和智慧型方塊。詳情請參閱「使用智慧型方塊預覽連結」。
const decoratedText =
CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
const cardSection = CardService.newCardSection().addWidget(decoratedText);
const card = CardService.newCardBuilder().addSection(cardSection).build();
const linkPreview = CardService.newLinkPreview().setPreviewCard(card).setTitle(
'Smart chip title');
內容詳盡的說明文件
printJson()
列印此物件的 JSON 表示法。這項設定僅供偵錯。
回攻員
String
setLinkPreviewTitle(title)
設定在預覽資訊卡上方連結預覽畫面中顯示的標題。如果未設定,連結預覽畫面會顯示 PreviewCard
的標頭。
const linkPreview =
CardService.newLinkPreview().setLinkPreviewTitle('Link preview title');
參數
名稱 | 類型 | 說明 |
title | String | 連結預覽的標題。 |
回攻員
LinkPreview
:這個物件用於鏈結。
setPreviewCard(previewCard)
設定資訊卡,顯示第三方或非 Google 服務的連結相關資訊。
const decoratedText =
CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
const cardSection = CardService.newCardSection().addWidget(decoratedText);
const card = CardService.newCardBuilder().addSection(cardSection).build();
const linkPreview = CardService.newLinkPreview().setPreviewCard(card).setTitle(
'Smart chip title');
參數
名稱 | 類型 | 說明 |
previewCard | Card | 預覽資訊卡。 |
回攻員
LinkPreview
:這個物件用於鏈結。
setTitle(title)
設定連結預覽畫面中智慧型方塊顯示的標題。如果未設定,智慧型方塊會顯示 PreviewCard
的標頭。
const linkPreview = CardService.newLinkPreview().setTitle('Smart chip title');
參數
名稱 | 類型 | 說明 |
title | String | 智慧型方塊的標題。 |
回攻員
LinkPreview
:這個物件用於鏈結。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eLinkPreview\u003c/code\u003e is a card action that displays a preview card and smart chip within a host application.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can customize the title shown in the link preview and smart chip using \u003ccode\u003esetLinkPreviewTitle()\u003c/code\u003e and \u003ccode\u003esetTitle()\u003c/code\u003e, respectively.\u003c/p\u003e\n"],["\u003cp\u003eA preview card, created using \u003ccode\u003eCardService\u003c/code\u003e, provides detailed information about the linked content within the \u003ccode\u003eLinkPreview\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003esetPreviewCard()\u003c/code\u003e is used to attach this custom preview card to the \u003ccode\u003eLinkPreview\u003c/code\u003e action.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eprintJson()\u003c/code\u003e method is available for debugging purposes to inspect the JSON representation of the \u003ccode\u003eLinkPreview\u003c/code\u003e object.\u003c/p\u003e\n"]]],[],null,["# Class LinkPreview\n\nLinkPreview\n\nCard action that displays a link preview card and smart chip in the host app. For more\ninformation, refer to [Preview links\nwith smart chips](https://developers.google.com/apps-script/add-ons/editors/gsao/preview-links).\n\n```javascript\nconst decoratedText =\n CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');\n\nconst cardSection = CardService.newCardSection().addWidget(decoratedText);\n\nconst card = CardService.newCardBuilder().addSection(cardSection).build();\n\nconst linkPreview = CardService.newLinkPreview().setPreviewCard(card).setTitle(\n 'Smart chip title');\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------|------------------|------------------------------------------------------------------------------------------------|\n| [printJson()](#printJson()) | `String` | Prints the JSON representation of this object. |\n| [setLinkPreviewTitle(title)](#setLinkPreviewTitle(String)) | [LinkPreview](#) | Sets the title that displays in the link preview above the preview card. |\n| [setPreviewCard(previewCard)](#setPreviewCard(Card)) | [LinkPreview](#) | Sets the card that displays information about a link from a third-party or non-Google service. |\n| [setTitle(title)](#setTitle(String)) | [LinkPreview](#) | Sets the title that displays in the smart chip for the link preview. |\n\nDetailed documentation\n----------------------\n\n### `print``Json()`\n\nPrints the JSON representation of this object. This is for debugging only.\n\n#### Return\n\n\n`String`\n\n*** ** * ** ***\n\n### `set``Link``Preview``Title(title)`\n\nSets the title that displays in the link preview above the preview card. If unset, the link\npreview displays the header of the `Preview``Card`.\n\n```javascript\nconst linkPreview =\n CardService.newLinkPreview().setLinkPreviewTitle('Link preview title');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|--------------------------------|\n| `title` | `String` | The title of the link preview. |\n\n#### Return\n\n\n[LinkPreview](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Preview``Card(previewCard)`\n\nSets the card that displays information about a link from a third-party or non-Google service.\n\n```javascript\nconst decoratedText =\n CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');\n\nconst cardSection = CardService.newCardSection().addWidget(decoratedText);\n\nconst card = CardService.newCardBuilder().addSection(cardSection).build();\n\nconst linkPreview = CardService.newLinkPreview().setPreviewCard(card).setTitle(\n 'Smart chip title');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|--------------------------------------------------|-------------------|\n| `preview``Card` | [Card](/apps-script/reference/card-service/card) | The preview card. |\n\n#### Return\n\n\n[LinkPreview](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Title(title)`\n\nSets the title that displays in the smart chip for the link preview. If unset, the smart chip\ndisplays the header of the `Preview``Card`.\n\n```javascript\nconst linkPreview = CardService.newLinkPreview().setTitle('Smart chip title');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|------------------------------|\n| `title` | `String` | The title of the smart chip. |\n\n#### Return\n\n\n[LinkPreview](#) --- This object, for chaining."]]