How to get data from Google spreadsheet by specific value in php? - php

I am trying to get data from Google spreadsheet by some specific value, currently I have tried the following method:
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle(APPLICATION_GOOGLE_SPREADSHEETS_BOOK);
$worksheetFeed = $spreadsheet->getWorksheets();
$worksheet = $worksheetFeed->getByTitle(APPLICATION_GOOGLE_SPREADSHEETS_SHEET);
It works fine when I use this:
$listFeed = $worksheet->getListFeed(array("sq" => "name = henryhwong", "reverse" => "true"));
but when it do the same for email it gives error:
$listFeed = $worksheet->getListFeed(array("sq" => "email = henryhwong#gmail.com", "reverse" => "true"));
The error is because of "#", if search anything else which doesn't contain "#" sign then it works perfectly, I am unable to find the cause behind this.

Had a similar problem before. Try put email in double quotes:
$listFeed = $worksheet->getListFeed(array("sq" => 'email = "henryhwong#gmail.com"', "reverse" => "true"));

Try this code below. Hope it helps you.
$listFeed = $worksheet->getListFeed(array("sq" => "email" = "henryhwong#gmail.com", "reverse" => "true"));

Related

Telegram bot doesn't answer

I'm using the package of eleirbag89 http://eleirbag89.github.io/TelegramBotPHP to create my bot on telegram.
I'm having some issues on it, it doesn't answer me on telegram but the code is correct (it answered in the past and nothing has changed).
How can I debug the code to see if everything is good?
Could be a problem of SSL certificate?
This is the simple code I used to test the bot after the issue:
require '../vendor/autoload.php';
$BOT_TOKEN = "[bot:token]";
$telegram = new Telegram($BOT_TOKEN);
$result = $telegram->getData();
$text = $result['message']['text'];
$chat_id = $result['message']['chat']['id'];
if ($text == "/test") {
$msg = 'Test is good';
$content = array('chat_id' => $chat_id, 'text' => $msg);
$telegram->sendMessage($content);
}
But it doesn't answer me :(
$token = "Token";
$link01 = "https://api.telegram.org/bot".$token;
$updates = file_get_contents('php://input');
$updates = json_decode($updates, TRUE);
$msgID = $updates['message']['from']['id'];
$name = $updates['message']['from']['first_name'];
try this one.
Could be a problem of SSL certificate?
YES
You need to set webhook,
Only you can set webhook, If it is HTPS
Here is how to set web hook

Amazon SES + PHP

I'm trying to set up amazon SES with PHP. I've scoured the internet and the documentation for AWS PHP SDK but I only see outdated scripts on how to include the actual library and send e-mail. Does anyone here have a working script for using Amazon SES with PHP?
This is the closest I've found to test the script but it doesn't work:
require 'src/aws.phar';
use Aws\Common\Enum\Region;
use Aws\Ses\SesClient;
try {
$ses = SesClient::factory(array(
'key' => 'AKIAJ4ERVU6XXXXXXX',
'secret' => 'kMgagzJmB4Xjw7UD+Md0KNgW+CTE2jCXXXXX/',
'region' => Region::US_EAST_1
));
$ses->verifyEmailIdentity( array(
'EmailAddress' => 'jason#aol.com'
));
}
catch( Exception $e )
{
echo $e->getMessage();
}
First, you would want to disable/delete and generate new keypairs so that you would not have to face bad situation as there are scrapers/bots and people who might misuse your access key-pairs.
As for your original question, you didn't describe what didn't work for you. Anyway, since you wanted a working version, check the source code of this: https://github.com/daniel-zahariev/php-aws-ses which will give you enough idea to get yours working.
This is the working code that i got for you, let me know if this helps
<?php
require 'aws.phar';
use Aws\Ses\SesClient;
$client = SesClient::factory(array('region'=>'us-east-1','version'=>
'latest','credentials' => array('key' => 'xxxxx','secret' => 'xxxxxx',)));
$msg = array();
$msg['Source'] = $message['from'];
$msg['Destination']['ToAddresses'][] = $to_address;
$msg['ReplyToAddresses'][] = $from;
$msg['Message']['Subject']['Data'] = $subject;
$msg['Message']['Subject']['Charset'] = "UTF-8";
$msg['Message']['Body']['Html']['Data'] = $body;
$msg['Message']['Body']['Html']['Charset'] = "UTF-8";
try{
$result = $client->sendEmail($msg);
$logmsg = "Passed ".from." - ".to_address;
} catch (Exception $e) {
$logmsg = "Failed ".$message['from']." - ".$to_address;
error_log('Failed Email '.from." - ".$to_address);
}

Changing Email Passwords With cPanel XML API in PHP

I've been jogging my mind on how to enable my users to change their passwords using the cPanels XML API. I've googled, played with example code, and could not find anything that remotely works. Can someone please tell me what I'm doing wrong? Thanks!
require_once('../includes/xmlapi.php');
$ip = '127.0.0.1';
$root_pass = 'secret';
$account = 'accountna';
$email_account = $_POST['email'];
$email_domain = "mydomain.com";
$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);
$xmlapi->set_debug(1);
$args = array(
'domain'=>$email_domain,
'email'=>$email_account
);
if ($xmlapi->api2_query($account, "Email", "passwdpop", array( 'domain' => "domain name", 'email' => "user name", 'password' => "new password") )) {
echo "Success!";
};
you neet to set port!
before password_auth
$xmlapi->set_port ( 2083 );
$xmlapi->password_auth("root",$root_pass);

Salesforce API: Error on ->update(), "INVALID_TYPE: Must send a concrete entity type."

I've been researching this and trying many variations based off my understanding of how to update a record in an SObject, but I keep getting the following error:
SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: Must send a concrete entity type. in /home/public_html/soapclient/SforceBaseClient.php:509
I am able to login successfully to the page, but when I execute the code below, I am getting the error listed above.
$fieldsToUpdate = array (
"Name"=>$_POST['Name']
);
$sObject = new SObject();
$sObject->Id = $_POST['prospectID']; // this is the Id of the record
$sObject->fields = $fieldsToUpdate;
$sObject->type = 'Prospect__c'; // this is the API name of custom object
try {
$response = $mySforceConnection->update($sObject);
} catch (Exception $e) {
echo $e;
}
I am using PHP Toolkit 13.0 from the Force.com developer docs, but not able to get to the bottom of this error. Also, I am using the Enterprise WSDL in sandbox mode, and have the proper wsdl xml assigned.
Thanks.
sObject is the base type for all other Salesforce objects that can be updated. When using the enterprise API (SOAP), you'll need to pass instances that derive from sObject. (Lead, Contact, and Account are examples)
Here is the documentation for the update() method as well.
You need to supply an object type as the second update() argument. Also, the first argument of the update() method must be an array of objects you'd like to update:
$response = $mySforceConnection->update(array($object), 'Prospect__c');
Also, you do not need to use any object classes provided by the toolkit, a simple StdClass should work:
$prospect = new StdClass();
$prospect->Id = '006....';
$prospect->Name 'Foobar';
$response = $mySforceConnection->update(array($prospect), 'Prospect__c');
FYI, I have never found a way to update multiple object types at once, but you can update a batch of the same type of objects, hence why the first parameter needs to be an array. The Salesforce toolkit doesn't automatically account for someone passing a single object (i.e. it doesn't wrap it in an array for you). I have always used an abstraction layer between my application logic and Salesforce's SOAP toolkit, which provides conveniences like I just described.
if your are using Partner wsdl
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once ('../userAuth.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
/*--------------------------------------------------------\
| Please manage the values for OBJECT ID from file
| userAuth.php
\--------------------------------------------------------*/
$fieldsToUpdate = array (
'FirstName' => 'testupdate',
'City' => 'testupdateCity',
'Country' => 'US'
);
$sObject1 = new SObject();
$sObject1->fields = $fieldsToUpdate;
$sObject1->type = 'Lead';
$sObject1->Id = $UPDATEOBJECTID1;
$fieldsToUpdate = array (
'FirstName' => 'testupdate',
'City' => 'testupdate',
'State' => 'testupdate',
'Country' => 'US'
);
$sObject2 = new SObject();
$sObject2->fields = $fieldsToUpdate;
$sObject2->type = 'Lead';
$sObject2->Id = $UPDATEOBJECTID2;
$sObject2->fieldsToNull = array('Fax', 'Email');
$response = $mySforceConnection->update(array ($sObject1, $sObject2));
print_r($response);
} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo $e->faultstring;
}
?>
else for enterprises wsdl use
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../userAuth.php');
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
/*--------------------------------------------------------\
| Please manage the values for OBJECT ID from file
| userAuth.php
\--------------------------------------------------------*/
$sObject1 = new stdclass();
$sObject1->Id = $UPDATEOBJECTID1;
$sObject1->FirstName = 'testupdate';
$sObject1->City = 'testupdateCity';
$sObject1->Country = 'US';
$sObject2 = new stdclass();
$sObject2->Id = $UPDATEOBJECTID2;
$sObject2->FirstName = 'testupdate';
$sObject2->City = 'testupdate';
$sObject2->State = 'testupdate';
$sObject2->Country = 'US';
$sObject2->fieldsToNull = array('Fax', 'Email');
$response = $mySforceConnection->update(array ($sObject1, $sObject2), 'Lead');
print_r($response);
} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo $e->faultstring;
}
?>

Google contacts API is ignoring the userDefinedField setting

I am trying to add a contact while at the same time including a userDefinedField. The code below works and adds the contact with the correct information however the userDefined field is missing. If I purposefully misspell one of the attributes, when I post the api falls over telling me it is missing an element, however if I fix the misspelling it does not include the userDefined Field.
Maybe I am missing something tiny but I really cannot see why it would simply be ignored. Does anyone have any ideas?
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
$email = "<email>";
$password = "<password>";
$contactName = $requestData['name'];
$contactAddress = $requestData['email'];
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $password,"cp");
$gdata = new Zend_Gdata($client);
$entry = $gdata->newEntry();
$extensionElements = $entry->getExtensionElements();
$extension = new Zend_Gdata_App_Extension_Element('email', null,'http://schemas.google.com/g/2005');
$attributes['address'] = array('name'=>'address', 'value' =>$contactAddress);
$attributes['rel'] = array('name'=>'rel', 'namespaceUri'=>null,'value' => 'http://schemas.google.com/g/2005#work');
$attributes['primary'] = array('name'=>'primary', 'namespaceUri' =>null, 'value' => 'true');
$extension->setExtensionAttributes($attributes);
$attributes = null;
// adds the new email extension element to the entry's exenstions elemensts array
array_push( $extensionElements, $extension );
$extension = new Zend_Gdata_App_Extension_Element('userDefinedField', null, 'http://schemas.google.com/contact/2008');
$attributes['key'] = array('name'=>'key', 'value' =>'customGUID');
$attributes['value'] = array('name'=>'value', 'value' => $this->guid());
$extension->setExtensionAttributes($attributes);
$attributes = null;
array_push( $extensionElements, $extension );
$extension = new Zend_Gdata_App_Extension_Element('groupMembershipInfo', null, 'http://schemas.google.com/contact/2008');
$attributes['deleted'] = array('namespaceUri'=>null,'name'=>'deleted', 'value' => 'false');
if ("manufacturers" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $MANUFACTURER_GROUP_URI);
} elseif ("distributors" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $DISTRIBUTOR_GROUP_URI);
} elseif ("clients" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $CLIENT_GROUP_URI);
}
$extension->setExtensionAttributes($attributes);
array_push( $extensionElements, $extension );
$entry->setExtensionElements($extensionElements);
$entry->title = $gdata->newTitle($contactName);
$entry->setExtensionElements($extensionElements);
$entryResult = $gdata->insertEntry($entry,"http://www.google.com/m8/feeds/contacts/$email/full");
I have already received a lot of help from the following posts, but didn't see anything to fix the issue:
http://www.google.com/support/forum/p/apps-apis/thread?tid=22ec941b7ac4ffc1&hl=en
http://groups.google.com/group/google-contacts-api/browse_thread/thread/be92586871a56046/95ec69573ca0f490?pli=1
http://www.ibm.com/developerworks/opensource/library/x-phpgooglecontact/index.html
I managed to figure it out.
I was not specifying which version of the API to use, so as soon as I specified the latest version using the below code, the userDefinedField appeared in Contacts as required.
$gdata->setMajorProtocolVersion(3);
$gdata->setMinorProtocolVersion(null);
Hope this helps others with similar questions.

Categories