Google_Sheet_Helpers::api_get_spreadsheets_from_drive( $drive_id )
Method api_get_spreadsheets_from_drive
Parameters Parameters
- $drive_id
-
(Required)
Return Return
(void)
Source Source
File: src/integrations/google-sheet/helpers/google-sheet-helpers.php
public function api_get_spreadsheets_from_drive( $drive_id ) { $client = $this->get_google_client(); if ( ! $client ) { return; } $response = wp_remote_post( $this->automator_api, array( 'method' => 'POST', 'body' => array( 'action' => 'list_files', 'access_token' => $client, 'drive_id' => $drive_id, 'api_ver' => '2.0', 'plugin_ver' => InitializePlugin::PLUGIN_VERSION, ), ) ); $body = null; $fields = array(); $fields[] = array( 'value' => '-1', 'text' => __( 'Select a Google Sheet', 'uncanny-automator' ), ); if ( is_array( $response ) && ! is_wp_error( $response ) ) { $body = json_decode( wp_remote_retrieve_body( $response ) ); if ( $body && $body->statusCode == 200 ) { foreach ( $body->data as $item ) { $fields[] = array( 'value' => $item->id, 'text' => $item->name, ); } } else { $fields['-1'] = __( 'Google returned an error: ', 'uncanny-automator' ) . $body->error->description; } } else { $fields['-1'] = __( 'Google returned an error. Please try again in a few minutes.', 'uncanny-automator' ); } return $fields; }
Expand full source code Collapse full source code View on Github