我正在使用google API的库: composer require google/apiclient:^2.0来自:https://developers.google.com/docs/api/quickstart/php
谁能教我如何创建新的谷歌文档文件,然后插入文本和图像的API?
发布于 2019-03-21 15:40:53
有一个可以使用InsertInlineImageRequest
方法将图像插入到文档中的documentation。
$requests = array();
$requests[] = new Google_Service_Docs_Request(array(
'insertInlineImage' => array(
'uri' => 'https://www.gstatic.com/images/branding/product/1x/docs_64dp.png',
'location' => array(
'index' => 1,
),
'objectSize' => array(
'height' => array(
'magnitude' => 50,
'unit' => 'PT',
),
'width' => array(
'magnitude' => 50,
'unit' => 'PT',
),
)
)
));
// Execute the requests.
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
'requests' => $requests
));
$response =
$docsService->documents->batchUpdate(DOCUMENT_ID, $batchUpdateRequest);
该方法将图像作为新的ParagraphElement
插入,其中InlineObjectElement
的长度为1,其中startIndex
是请求的位置。您还可以选择指定一个大小来调整图像的大小。
https://stackoverflow.com/questions/55273369
复制相似问题