Google Sheet API - How to get all sheets name in spreadsheet file? - google-sheets-api

I use Google Sheet API Version 4.
And i want to get all sheets name what available in that spreadsheet file?
So if you have any way to do it, tell me please. Thanks

public function GoogleServiceSheets(){
$client = new \Google_Client();
$client->setApplicationName('Sheets');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig(GOOGLE_CREDENTIALS);
$service = new Google_Service_Sheets($client);
return $service;
}
public function getSheetID_SheetName($spreadsheetID){
$service = $this->GoogleServiceSheets();
$sheetNumberCounter = 1;
$spreadSheetArr = [];
$worksheetSheets = $service->spreadsheets->get($spreadsheetID)->sheets;
foreach($worksheetSheets as $sheet){
$id = $sheet->properties['sheetId'];
$name = $sheet->properties['title'];
$singleSheetArr = array(
'id'=>$id,
'name'=>$name
);
$spreadSheetArr[$sheetNumberCounter] = $singleSheetArr;
$sheetNumberCounter = $sheetNumberCounter + 1;
}
return $spreadSheetArr;
}

We can call spreadsheet object to get all information of spreadsheet.
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'your spredsheetid';
$sheetInfo = $service->spreadsheets->get($spreadsheetId);
$allsheet_info = $sheetInfo['sheets'];
$idCats = array_column($allsheet_info, 'properties');
Thanks

Google api lets do it.
You need to do api call:
https://spreadsheets.google.com/feeds/worksheets/key/public/basic?alt=json
Where the "key" is your spreadsheet.
Good luck!

Related

Questions regarding update of table on Prestashop

I'm trying to update ps_stock_available when I modify the product on Prestashop. But it's unsuccessfull. Could you help me please ?
public function hookActionUpdateQuantity(array $params)
{
$id_product = $params['id_product'];
$product = new Product((int)$id_product);
$id_category = $product->id_category_default;
$db = \Db::getInstance();
$request_loc='SELECT location FROM `'._DB_PREFIX_.'category_location` WHERE `id_category` = '.(int)$id_category;
$location = $db->getValue($request_loc);
$request_id_stock='SELECT id_stock_available FROM `'._DB_PREFIX_.'stock_available` WHERE `id_product` = '.(int)$id_product;
$id_stock_available = $db->getValue($request_id_stock);
$result = $db->update('stock_available', array('location' => $location), '`id_stock_available` = '.(int)$id_stock_available);
}
I have written this code but it doesn't seem to work.
in order to accomplish this task I would rely to the native StockAvailable class metehods getStockAvailableIdByProductId() and setLocation() (check the classes/stock/StockAvailable.php file).
Anyway your code seems to be correct, so I would definitely check for undefined variables and/or something not working in the $db->update statement.
In case, you can change it to :
$db->execute('UPDATE '._DB_PREFIX_.'stock_available SET `location` = "'.pSQL($location).'" WHERE id_stock_available = '.(int)$id_stock_available;

Kreait : verifySessionCookie() not found

I try to verify a session cookie from the $sessionCookieString = $auth->createSessionCookie($idToken, $oneWeek); which work normally.
But report say that the function is not found.
"Call to undefined method Kreait\Firebase\Auth::verifySessionCookie()"
Didn't understand why.
i have the latest version install.
--- Portion of code below ---
use Kreait\Firebase\Factory;
use Kreait\Firebase\Contract\Auth;
use Kreait\Firebase\Auth\UserQuery;
use Google\Cloud\Firestore\FirestoreClient;
use Kreait\Firebase\Auth\CreateSessionCookie\FailedToCreateSessionCookie;
public function doLogin() {
$factory = (new Factory)->withServiceAccount($this->ekonysJson );
$auth = $factory->createAuth();
$this->auth = $auth;
//print_r($auth);
$signInResult = $auth->signInWithEmailAndPassword("email#dot", "password");
$idToken = $signInResult->idToken();
`print_r($signInResult->refreshToken());`
$oneWeek = new \DateInterval('P7D');
$sessionCookieString = $auth->createSessionCookie($idToken, $oneWeek);
$verifiedSessionCookie = $auth->verifySessionCookie($sessionCookieString)
}
refer to doc https://firebase-php.readthedocs.io/en/stable/authentication.html#session-cookies
if you have any idea.... thanks
Solution for this problem

How to i can access to one of multi sheets in a spreadsheet

I'm newbie, i developing small project import csv to google sheets,
about part import csv to google sheets and create a sheet in spreadsheets i successed. How i can access to sheet that i created? Under is code to i create a sheet in spreadsheet ID. Thanks!!
$client = getClient();
$service = new Google_Service_Sheets($client);
$valueInputOption = 'USER_ENTERED';
$spreadsheetId = 'xxxxxxxxxxxxSPREADSHEETIDxxxxxxxxxx';
$title = date('m-d');
$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array( 'requests' => array('addSheet' => array('properties' => array('title' => $title )))));
$result = $service->spreadsheets->batchUpdate($spreadsheetId, $body);
The way of accessing the data of the google spreadsheets is as below:
/*
Assume the data structure of the Google Spreadsheet is:
NAME COLOR
==================
Apple red
Mango yellow
*/
// define sheet url
var dataSheetUrl =
'https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/edit';
// open one of the sheet named 'Fruit'
var dataSheet = SpreadsheetApp.openByUrl(dataSheetUrl).getSheetByName('Fruit');
// get sheet data
var data = dataSheet.getDataRange().getValues();
// loop through each row data and then log it
for (var i = 1, j = data.length; i < j; i++) {
Logger.log('NAME: ' + data[i][0]);
Logger.log('AGE: ' + data[i][1]);
}

sending email to multiple accounts using php ews

The below code is used for sending email using jamesiarmes/php-ews
in my application
$request = new \jamesiarmes\PhpEws\Request\CreateItemType();
$request->MessageDisposition = "SendOnly";
$request->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
$request->Items->Message->ItemClass = "IPM.Note";
$request->Items->Message->Subject = "exchange new mail";
$request->Items->Message->Body->BodyType = 'HTML';
$request->Items->Message->Body->_ = "This is a test mail as a part of exchange settings set up ";
$request->Items->Message->ToRecipients->Mailbox->EmailAddress = "rejith.rj#pitsolutions.com";
$response = $this->app['ews']->CreateItem($request);
But the problem is I can add only one email address as recipient, how can I add multiple email addresses in ToRecipients?
I checked out the php-ews documentation. You can create an array with multiple recipients this way:
$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = 'john.harris#domain.com';
$toAddresses[0]->Name = 'John Harris';
$toAddresses[1] = new EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = 'sara.smith#domain.com';
$toAddresses[1]->Name = 'Sara Smith';
And then add it to your object like this:
$request->Items->Message->ToRecipients = $toAddresses;
Try this and feedback me please.
Seems to me that your problem has not been solve yet?
Following works for me:
$toAddresses = array();
$toAddresses[0]="test#test.com";
$toAddresses[1]="test2#test.com";
$api = MailAPI::withUsernameAndPassword("server", "username", "password");
$message = new Type\MessageType();
$message->setBody('Some Text');
$message->setSubject('Test Subject');
$message->setToRecipients($toAddresses);

How to get output of a webpage in ActionScript 2

For Actionscript 2.0
Let's say this page
www.example.com/mypage
returns some html that I want to parse in Actionscript.
How do i call this page from Actionscript while getting back the response in a string variable?
use LoadVars():
var lv = new LoadVars();
//if you want to pass some variables, then:
lv.var1 = "BUTTON";
lv.var2 = "1";
lv.sendAndLoad("http://www.example.com/mypage.html", lv, "POST");
lv.onLoad = loadedDotNetVars;
function loadedDotNetVars(success)
{
if(success)
{
// operation was a success
trace(lv.varnameGotFromPage)
}
else
{
// operation failed
}
}
//if you dont want to send data, just get from it, then use just lv.Load(...) instead of sendAndLoad(...)
I understand. Use this code then:
docXML = new XML(msg);
XMLDrop = docXML.childNodes;
XMLSubDrop = XMLDrop[0].childNodes;
_root.rem_x = (parseInt(XMLSubDrop[0].firstChild));
_root.rem_y = (parseInt(XMLSubDrop[1].firstChild));
_root.rem_name = (XMLSubDrop[2].firstChild);
var htmlFetcher:LoadVars = new LoadVars();
htmlFetcher.onData = function(thedata) {
trace(thedata); //thedata is the html code
};
Use:
htmlFetcher.load("http://www.example.com/mypage");
to call.
I suppose you could use:
page = getURL("www.example.com/mypage.html");
And it would load the page contents on the page variable.