Google Sheet UpdateValuesResponse() - php

I update values in Google Sheet modifyed this quiqstartfile: https://developers.google.com/sheets/api/quickstart/php
After update i need response from google api that all is OK (it has not error). How to test that update success? How to make it?
I tried:
$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params);
$test=$result->UpdateValuesResponse();
printf($test);
And have error:
PHP Fatal error: Uncaught Error: Call to undefined method Google_Service_Sheets_UpdateValuesResponse::UpdateValuesResponse() in
/var/www/html/writegs.php:101 Stack trace:
> #0 {main} thrown in /var/www/html/writegs.php on line 101

Check the documentation here:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update
According to the PHP example given there, the response you get back from the update is an UpdateValuesResponse object. That's not a method.
So if you're just wanting to test you got a successful response, try:
$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params);
echo '<pre>', var_export($result , true), '</pre>', "\n";
$result = json_decode($result);
$updatedCells = $result->updatedCells;

Related

Error on integrating php and google sheets api

I am trying to integrate google sheets api with php so that I can capture html form data and append it to spreadsheet but I am facing a weird error.
Below is the php snippet:
$client = new \Google_Client();
$client->setApplicationName('WEBMONK_QUOTATION_REQUESTS');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig('../credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheets_id = '1S2LPDl5XmOEx4TQ3cR4yZ4SAALcxXRyxU5nFMU7RW0I';
$range = 'QUOTESHEET';
$sheet_rows = [
strval($datetime),
strval($name),
strval($email),
strval($url),
strval($extras)
];
$body = new Google_Service_Sheets_ValueRange(['values' => [$sheet_rows]]);
$params = ['valueInputOption' => 'RAW'];
$insert = ['insertDataOption' => 'INSERT_ROWS'];
$result = $service->spreadsheets_values->append(
$spreadsheets_id,
$range,
$body,
$params,
$insert
);
Here is the error I am getting:
<br />
<b>Fatal error</b>: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php:291
Stack trace:
#0 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(291): implode(Array, '&')
#1 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(190): Google_Service_Resource->createRequestUri('v4/spreadsheets...', Array)
#2 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient-services\src\Google\Service\Sheets\Resource\SpreadsheetsValues.php(64): Google_Service_Resource->call('append', Array, 'Google_Service_...')
#3 C:\xampp\htdocs\webric.org\api\post\insert.php(68): Google_Service_Sheets_Resource_SpreadsheetsValues->append('1S2LPDl5XmOEx4T...', 'QUOTESHEET', Object(Google_Service_Sheets_ValueRange), Array, Array)
#4 {main}
thrown in <b>C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php</b> on line <b>291</b><br />
So far, that I have understood, an implode() function in the Google lib is malfunctioning because of wrong argument type. But I couldn't find anything wrong with my above php code. I have gone through the google sheets and php integration procedures as mentioned here:
PHP with Google Sheets Quickstart
PHP version: 8.0.0,
Google API Client: 2.0
Please tell me where I am going wrong. Thanks in advance.
Just had the same issue after switching to PHP 8.0 (previously working fine with PHP 7.2).
The implode() function in PHP 8.0 has basically the two arguments switched compared to previous versions. I checked out the lastest version of the Resource.php file in the Google library, and you should see that the line 303 reflects those changes already.
I went to my Resource.php file and replaced
$requestUrl .= '?' . implode($queryVars, '&');
with
$requestUrl .= '?' . implode('&', $queryVars);
And it's working again. Hope it helped!
There must be a problem with your values
Verify it by modifying $body to
$body = new Google_Service_Sheets_ValueRange([
"values" => [[1, 2, 3]]
]);
If this request works for you - log [$sheet_rows] to compare the structure and see what is wrong.
PS: Apart from the Quickstart, there is aslo method specific documentation for PHP

Uncaught Error: Call to undefined method DB::execute()

I am using indieteq-php-my-sql-pdo-database-class I found on GitHub
I have created a little page to try and display some database information as seen below, however I receive the error below my test page script below;
My Test Page
<?php
require("Db.class.php");
$db = new Db();
$db->query("SELECT * FROM faction_territories");
if ($db->execute()) {
while ($row = $db->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>
<td>'.$row['territory_id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['density'].'</td>
<td>'.$row['sector'].'</td>
<td>'.$row['size'].'</td>
<td>'.$row['respect'].'</td>
<td>'.$row['faction_name'].'</td>
</tr>';
}
echo '</table>';
}
?>
Error
Fatal error: Uncaught Error: Call to undefined method DB::execute() in
/var/www/.../index.php:7 Stack trace: #0 {main} thrown in
/var/www/.../index.php on line 7
Questions
As you'll be able to tell, I'm somewhat new to PHP & PDO. Some nice pointers to where I am going wrong would be nice with any example code please.
The $db->query already execute the query. You just need to iterate over the result.
See here: https://github.com/wickyaswal/indieteq-php-my-sql-pdo-database-class/blob/master/Db.class.php#L189

PHP Connect to Sharepoint using Thybag\SharePointAPI

I have the following code
//$sp = new SharePointAPI('&&', '&&', 'https://&&.net/personal/zzz/_vti_bin/Lists.asmx?WSDL',);
//$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?SDL', 'NTLM');
$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?WSDL', 'SPONLINE');
$listContents = $sp->read('GetListCollection');
return $listContents;
Depending on which of the "new SharepointAPI" lines I execute, I get a different error.
Using "NTLM", I get the error: -
Uncaught exception 'Exception' with message 'Error'
in /home/shinksyc/public_html/sharepointUpload/src/Thybag/Auth/SoapClientAuth.php:129
Stack trace:
#0 [internal function]: Thybag\Auth\SoapClientAuth->__doRequest('<?xml
version="...', 'https://my.sp.m...', 'http://schemas....', 1, 0)
Using "SPONLINE", I get the error
'Error (Client) looks like we got no XML document'.
I am also slightly confused as to how to find out what the name of the lists may be that I get read.
Any help is much appreciated.
Thanks
Martin
The path to your xml must be local: in clear, log to your sharepoint, go to the url https://mySPsite/subsite/_vti_bin/Lists.asmx?WSDL
Download the XML and place it on your PHP server.
then
$sp = new SharePointAPI($login, $password, $localPathToWSDL, 'NTLM');

Zend_Mail_Storage_Pop3::removeMessage doesn't work

I have a e-mail driver. It get a list of e-mail accounts and receive and store messages, it works fine. But the messages deletion, at last line, doesn't works. Thats a part of code:
$arrPop3Config['host'] = $arrEmailconfiguracao['strPOPHost'];
$arrPop3Config['port'] = $arrEmailconfiguracao['intPOPPorta'];
$arrPop3Config['user'] = $arrEmailconfiguracao['strPOPUsuario'];
$arrPop3Config['password'] = $arrEmailconfiguracao['strPOPSenha'];
if($arrEmailconfiguracao['intAuth'] == '1') {
$arrPop3Config['ssl'] = 'SSL';
} else if($arrEmailconfiguracao['intAuth'] == '2') {
$arrPop3Config['ssl'] = 'TLS';
}
$objMail = new Zend_Mail_Storage_Pop3($arrPop3Config);
foreach($objMail as $intMensagemNum => $objMensagem) {
$strMensagemUniqueId = $objMail->getUniqueId($intMensagemNum);
$arrHeader = $objMensagem->getHeaders();
$strRemetente = $objMensagem->getHeader('from', 'string');
preg_match_all("/(.*)?<(.*)?>/", $strRemetente, $arrRemetente);
$strRemetenteNome = $arrRemetente[1][0];
$strRemetenteEmail = $arrRemetente[2][0];
$strTitulo = $objMensagem->getHeader('subject', 'string');
$objMensagemPart = $objMensagem;
while ($objMensagemPart->isMultipart()) {
$objMensagemPart = $objMensagem->getPart(1);
}
$strCorpo = $objMensagemPart->getContent();
$objDb->call(
'emailClienteRecebe'
,array(
'intEmailconfiguracao' => $arrEmailconfiguracao['intId']
,'strMensagemUniqueId' => $strMensagemUniqueId
,'strRemetenteNome' => $strRemetenteNome
,'strRemetenteEmail' => $strRemetenteEmail
,'strHeaders' => serialize($arrHeader)
,'strTitulo' => $strTitulo
,'strCorpo' => $strCorpo
)
);
$objMail->removeMessage($strMensagemUniqueId);
Php client return this message:
PHP Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'last request failed' in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php:189
Stack trace:
#0 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(221): Zend_Mail_Protocol_Pop3->readResponse(false)
#1 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(457): Zend_Mail_Protocol_Pop3->request('DELE GmailId12d...')
#2 /var/www/maru/Maru/Zend/Mail/Storage/Pop3.php(227): Zend_Mail_Protocol_Pop3->delete('GmailId12de8345...')
#3 /var/www/maru/drivers/recebe-emails/driver.php(82): Zend_Mail_Storage_Pop3->removeMessage('GmailId12de8345...')
#4 {main}
thrown in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php on line 189
Apparently the pop command "DELE GmailId1283038051edcc6e" is the problem. However, using a common e-mail client, like mozilla thunderbird, i've monitorated sent commands e the same command works fine.
Any ideas?
I know nothing about the Zend Pop3 client, only by looking at the online documentation.
The POP3 specification has a DELE command, taking a message number. You are supplying a string!
Therefore the server of course does not know what to do. The Zend POP3 method even states that the id supplied has to be of integer type in the removeMessage documentation.
If you look at the getNumberByUniqueId documentation, you will see that you should translate the unique ID to a message number before calling removeMessage.
Therefore, to fix your problem, you should replace your last line with:
$objMail->removeMessage($objMail->getNumberByUniqueId($strMensagemUniqueId));
And then I think everything will be fine.

How can I fix this PHP XML parsing error?

This is my first question :).
Im writing a little twitter app in PHP that sends a DMs to all your followers. What im trying to do right now is to get the list of followers. So through twitter api and getting all usernames but for some reason this parsing error appear. Im new to php(but not so much to programming), I actually started learning it yesterday so please be easy on me ;).
Here is the code:
$t= new twitter();
$t->username= $_GET["username"];
$t->password= $_GET["password"];
$fi = $t->followers();
$xml[$page] = new SimpleXMLElement($fi[2]);
$user1count=0;
while(isset($xml[$page]->user[0])){
foreach ($xml[$page]->user as $user) {
$userdet[(string)$user->screen_name]=array( ’screen_name’=> (string)$user->screen_name, ‘location’=>(string)$user->location, ‘description’=>(string)$user-> description, ‘profile_image_url’=> (string)$user-> profile_image_url, ‘url’=>(string)$user-> url, ‘name’=>(string)$user->name );
$user1details[$user1count]= (string)$user->screen_name;
$user1count++;
}
$page++;
$fi=getfilecontents($friendsurl.$username1."xml?page".$page);
if($fi[0]===false){
echo ("Error :".$fi[1]);
$err=new SimpleXMLElement($fi[2]);
echo " ".$err->error." ";
// echo ““;
die();
}
$xml[$page] = new SimpleXMLElement($fi[2]);
}
And the error said:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php:125 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php(125): SimpleXMLElement->__construct('') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php on line 125
Thank you! :)
It looks like $fi[2] is not a valid xml string. I am not 100% familiar with the twitter API, but I would do a var_dump($fi) and evaluate what is begin returned. From there, you should be able to figure out what is happening.

Categories