I want to insert more the one texts in google docs with multiple paragraph contents and also want to style them. I also followed this link https://developers.google.com/docs/api/reference/rest/v1/documents/request but I am unable to achieve this.
$requests [] = new Google_Service_Docs_Request(
[
'insertText' => [
'text' => 'Sample1n',
'location' => [
'index' => 1
]
]
],
[
'insertText' => [
'text' => 'sample2n',
'location' => [
'index' => 9
]
]
],
[
'updateParagraphStyle' => [
'range' => [
'startIndex' => 1,
'endIndex' => 8
],
'paragraphStyle' => [
'namedStyleType' => 'HEADING_1'
],
'fields' => 'namedStyleType'
]
],
[
'updateParagraphStyle' => [
'range' => [
'startIndex' => 9,
'endIndex' => 17
],
'paragraphStyle' => [
'namedStyleType' => 'NORMAL_TEXT'
],
'fields' => 'namedStyleType'
]
],
[
'updateTextStyle' => [
'range' => [
'startIndex' => 9,
'endIndex' => 16
],
'textStyle' => [
'link' => [
'url' => 'https://www.google.com'
]
],
'fields' => 'link'
]
]
);
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
'requests' => $requests
));
$response = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
I am doing in this way and getting this error
PHP Fatal error: Uncaught GoogleServiceException: {
"error": {
"code": 400,
"message": "Invalid requests[0]: No request set.",
"errors": [
{
"message": "Invalid requests[0]: No request set.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
Can anyone help me out with this. It would be a great help and i need it in PHP code.