i am inserting some data to an salesforce object named as Application__c from php using Soapclient. After connection successfull, i have written following code
$applications = array();
$updateFields = array();
if($_POST['savingsAccountBankName'] != ''){
$updateFields['savings_account_bank_name__c']= $_POST['savingsAccountBankName'];
}
if($_POST['AutoMake'] != ''){
$updateFields['Auto_make__c']= $_POST['AutoMake'];
}
if($_POST['AutoLicense'] != ''){
$updateFields['Auto_license__c']= $_POST['AutoLicense'];
}
$sObject = new sObject();
$sObject->type = 'Application__c';
$sObject->fields = $updateFields;
array_push($applications, $sObject);
try {
$results = $sforceClient->create($applications,'Application__c');
foreach ($results as $result)
{
$errMessage = $result->errors->message;
echo $errMessage;
}
} catch (Exception $e) {
echo 'Salesforce Upsert Error. Please try again later.';
echo '<pre>';
print_r($e);
echo '</pre>';
}
i am getting error "Trying to get property of non-object" at line "$errMessage = $result->errors->message;". What is the problem?
thanks
Be aware that $result is an array..
Try this :
if (!isset($result[0]->success) || ($result[0]->success!=1)) {
$strErrCode = isset($result[0]->errors[0]->statusCode)?
$result[0]->errors[0]->statusCode:'CANNOT_INSERT';
$strErrMsg = isset($result[0]->errors[0]->message)?
$result[0]->errors[0]->message:'Error Trying to insert';
$arrResult = array(
'errorCode' => $strErrCode,
'errorMsg' => $strErrMsg,
'id' => '',
);
error_log( 'Error Trying to insert - [' . $strErrMsg . '] - [' . $strErrCode . ']');
}
if (isset($result[0]->success) && ($result[0]->success==1)) {
$arrResult = array(
'errorCode' => 'SUCCESS_INSERT',
'errorMsg' => 'Insert Success',
'id' => isset($result[0]->id)?$result[0]->id:'1',
);
error_log( 'Success insert - [' . (isset($result[0]->id)?$result[0]->id:'1') . ']');
}
This means that whatever $results contains, it is not an object. Try doing a var_dump() on the variable $results and see what is actually in there. Then you can properly reference it.
Related
I am using the below function to get the like_count and the comments_count of user's last 10 instagram posts. However it returns invalid amounts. When I visit the instagram profile and add up the likes of last 10 posts it shows a greater value than the value recorded in the database. I was wondering if I have to pass any additional parameters with the business_discovery request?
Any help is appreciated.
/**
* Get post engagment ratio
*/
public function getPostEngagmentRatio()
{
try {
$userResponse = $this->fb->get(
'/'.$this->instagram_user_id.'?fields=username',
$this->page_access_token
);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $userResponse->getGraphNode();
$userResponse = $graphNode->asArray();
if (empty($userResponse)) {
$response = array(
'status' => 'error',
'message' => 'not able to find instagram user'
);
return $response;
}
$this->instagram_user_name = $userResponse['username'];
try {
$businessDiscoveryResponse = $this->fb->get(
'/'.$this->instagram_user_id.'?fields=business_discovery.username('.$this->instagram_user_name.'){followers_count,media_count,media{comments_count,like_count}}',
$this->page_access_token
);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $businessDiscoveryResponse->getGraphNode();
$businessDiscoveryResponse = $graphNode->asArray();
if (empty($businessDiscoveryResponse)) {
$response = array(
'status' => 'error',
'message' => 'not able to get user business discovery data'
);
return $response;
}
if (count($businessDiscoveryResponse['business_discovery']['media']) > 10) {
$total_posts = 10;
$breakloop = true;
} else {
$total_posts = count($businessDiscoveryResponse['business_discovery']['media']);
$breakloop = false;
}
$posts = array(
'likes' => 0,
'comments' => 0,
'total_posts' => $total_posts,
'engagement_ratio' => 0,
);
$posts['followers_count'] = $businessDiscoveryResponse['business_discovery']['followers_count'];
foreach ($businessDiscoveryResponse['business_discovery']['media'] as $key => $value) {
if ($breakloop && $key == 10) {
break;
}
//bug fix : undefined index like_count
if (isset($value['like_count'])) {
$posts['likes'] += $value['like_count'];
}
if (isset($value['comments_count'])) {
$posts['comments'] += $value['comments_count'];
}
}
return $posts;
}
I am trying to send SMS through RingCentral. This is the error I am getting below.
Fatal error: Uncaught Exception: Response has unsuccessful status in /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Http/Client.php:39 Stack trace: #0 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(276): RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request)) #1 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(363): RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array) #2 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(183): RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array) #3 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/includes/ring-central.class.php(26): RingCentral\SDK\Platform\Platform->login(Array, '#Gc090486', '101') #4 /Applicati in /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Http/Client.php on line 50
<?php
use RingCentral\SDK\SDK;
define("FAILED", 1);
define("LOCKED", 2);
class RingCentralConnection {
private $_sdk;
private $_platform;
function __construct($clientId, $secret) {
}
//https://platform.ringcentral.com/restapi/v1.0/account/159048008/extension/171857008/call-log?dateFrom=2012-08-26
public function sendSMS($from, $to, $text) {
$_credentials = require (getPluginDir().'/includes/credentials.php');
$_sdk = new SDK($_credentials['appKey'], $_credentials['appSecret'], $_credentials['server'], '2FA Demo', '1.0.0');
//print_r($_sdk);
$_platform = $_sdk->platform();
try {
$_platform->login($_credentials['username'], $_credentials['extension'], $_credentials['password']);
// $code = generateRandomCode(6);
// $myNumber = $_credentials['username'];
// try {
// $response = $_platform->post('/account/~/extension/~/sms', array(
// 'from' => array('phoneNumber' => $myNumber),
// 'to' => array(array('phoneNumber' => $to)),
// 'text' => $message
// ));
// $status = $response->json()->messageStatus;
// echo $status;
// if ($status == "SendingFailed" || $status == "DeliveryFailed") {
// //$db->close();
// createResponse(new Response(FAILED, "RC server connection error. Please try again."));
// } else {
// //$timeStamp = time();
// //$query = "UPDATE users SET code= " . $code . ", codeexpiry= " . $timeStamp . " WHERE email='" . $email . "'";
// //$db->query($query);
// //$db->close();
// createResponse(new Response(LOCKED, $message));
// }
// } catch (ApiException $e) {
// //$db->close();
// $this->createResponse(new Response(FAILED, "RC server connection error. Please try again in."));
// }
} catch (ApiException $e) {
//$db->close();
//print_r($e);
$this->createResponse(new Response(FAILED, "RC server connection error. Please try again out."));
}
}
function createResponse($res) {
$response = json_encode($res);
echo $response;
}
function databaseError() {
$res = new Response(UNKNOWN, "Unknown database error. Please try again.");
$response = json_encode($res);
die($response);
}
}
class Response {
function __construct($error, $message) {
$this->error = $error;
$this->message = $message;
}
public $error;
public $message;
}
//credentials
return array(
'username' => '+13128589951',
'extension' => '101', // extension number
'password' => '',
'appKey' => '',
'appSecret' => '',
'server' => 'https://platform.devtest.ringcentral.com'// for production - https://platform.ringcentral.com
);
Im trying to get the text out xpath/html using php..but not successful any idea.
Example:
https://safeweb.norton.com/report/show?url=google.com
My xpath (This is correct i already double check)
//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b
I want to get a result to appear here <div> result </div> using php
Below is my code:
<?php
public function getNortonSafe($domain)
{
try
{
$callback_url = "https://safeweb.norton.com/report/show?url=google.com"; //. $domain;
$curl_response = $this->curl->get($callback_url);
if ($curl_response->headers['Status-Code'] == "200") {
libxml_use_internal_errors(TRUE);
$this->dom_doc->loadHTML($curl_response);
libxml_use_internal_errors(FALSE);
$xpath = new DOMXPath($this->dom_doc);
$tmp = $xpath->query('//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b')->item(0)->textContent);
$tmp = explode(' ', trim($tmp));
$norton_site_test = str_replace(",", "", $tmp[0]);
} else {
$norton_site_test = "0";
}
$response = array(
'status' => 'success',
'data' => array(
'norton_site_test' => filter_var($norton_site_test, FILTER_SANITIZE_STRING)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
}
?>
HTML
<body>
<p id="norton_site_test"> result-text-here </p>
</body>
When executing the $xpath->query('some xpath here')->text(0) line an error occurs: Fatal error: Call to undefined method DOMNodeList::text(). Please check your PHP error reporting settings.
DOMXPath::query method returns DOMNodeList object that has only item method (see DOMNodeList).
You need to call:
$xpath->query('some xpath here')->item(0)->textContent
to get the text content of the first node from the received DOMNodeList object.
Just an Update regarding this code, and thank you to #camelsWrite - its working Now! with this clean code and tested:
public function getNortonSafe($domain)
{
try
{
$callback_url = "https://safeweb.norton.com/report/show?url= . $domain; //e.g $url: "https://safeweb.norton.com/report/show?url=google.com
$curl_response = $this->curl->get($callback_url);
if ($curl_response->headers['Status-Code'] == "200") {
libxml_use_internal_errors(TRUE);
$this->dom_doc->loadHTML($curl_response);
libxml_use_internal_errors(FALSE);
$xpath = new DOMXPath($this->dom_doc);
$tmp = $xpath->query('//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b')->item(0)->textContent);
$tmp = explode(' ', trim($tmp));
$norton_site_test = str_replace(",", "", $tmp[0]);
} else {
$norton_site_test = "0";
}
$response = array(
'status' => 'success',
'data' => array(
'norton_site_test' => filter_var($norton_site_test)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
} ?>
I am using php and mongodb. I want to use findandmodify. My field is { "_id" : ObjectId("58d37e612d4ffa498b99c2d4"), "userid" : "1234", "active_time" : "hai" }
I want to modify active_time. For example change the value "hai" to "1234"
I am using MongoDB\Driver\Manager.
try {
$mng = new MongoDB\Driver\Manager("mongodb://username:password#localhost:27017/db");
$userid = '1234';
$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
$command = new MongoDB\Driver\Command($retval);
$cursor = $manager->executeCommand('db.online', $command);
} catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
echo "In file:", $e->getFile(), "\n";
echo "On line:", $e->getLine(), "\n";
}
It shows the error is
Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Manager::findAndModify()
in line
$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
How it possible? please help me?
I got the answer. Change the findAndModify to update. The modified code is shown below.
$bulk->update(
array("userid" => '1234'), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
$mng->executeBulkWrite("browser.online", $bulk);
if(!empty($mng)) {
echo "success";
} else {
echo "not";
}
I've inherited some code from an ex-colleague and as it has recently been put into production it is causing us some issues. I'm not a php developer so apologies if this appears vague but it has fallen to me (don't ask!).
We are calling a function getLoan() to pre-populate an application form from an existing application. This should return an array, but I am receiving the stdClass error.
$result = getLoan(); //this is the line that is erroring
if (isset($result->GetResult->Debtor->Addresses->Address[0])) $current_address = clone $result->GetResult->Debtor->Addresses->Address[0];
else $current_address = clone $result->GetResult->Debtor->Addresses->Address;
if ($result === false)
{
echo("No LID given");
die;
}
$attr = 'selected';
and the function:
function getLoan() {
//globals
/*
global $client;
global $test;
global $result;
*/
global $thisurl;
if (isset($_GET['LID']))
$pLoanID = $_GET['LID'];
else
return false;
$test = array(
"pLoanID" => $pLoanID,
);
//print_r($Address); //print address object as a test
//send to gateway starts**********
$url = "https://www.blahblah.asmx?WSDL";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
try {
$result = $client->Get($test);
}
catch(Exception $e) {
//header("Location: http://" . $_SERVER['REMOTE_ADDR'] . "/application-form-new");
print_r($e);
exit;
}
$thisurl = "continue-app?LID=" . $pLoanID;
if (isset($result)) return $result;
else return false;
}
How can I assign the returned value from the function to $result as an array?
Many thanks
array = json_decode(json_encode(object),true);