I tried to integrate an API that built-in laravel and now I have to use that API's response into the Codeigniter project, I'm developing a Codeigniter project(I'm not familiar with this framework and it's my first time working with this),
I finally could do it, I'm getting a response from an API
$result = curl_exec($response);
$rs=json_decode($result,true); print_r($rs);
return $rs;
Array(
[user] =>
Array(
[user_no] => PMRQ3fVd6eGEvd5aO9MDJg()() [name] => Anthony [middle_name] => S [lastname] => Mosteller [email] => AnthonyMosteller#test.net
)
)
and desperately trying to access the object full name, email, and user_no into my controller
But I am stuck now.
controller code:
$user=$this->userapi->userapicall($user_url,$token);
$this->session->set_userdata('username',$user['name']); // here want to use full name (name+middle_name+lastname)
$this->session->set_userdata('useremail',$user['email']);
I'm getting an error for name and email
A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: controllers/auth.php
Line Number: 106
Do I need to create for each loop or seems something really silly mistake I make
I would appreciate an example of this.
$rs = json_decode($result,true); print_r($rs);
Here you are getting a multidimensional array. As per your code sample it looks like -
$rs = ['user' => ['user_no' => 'PMRQ3fVd6eGEvd5aO9MDJg', 'name' => 'Anthony', 'middle_name' => 'S', 'lastname' => 'Mosteller', 'email' => 'AnthonyMosteller#test.net']];
So if are trying to access user's name in controller -
$this->session->set_userdata('username',$user['user]['name']);
This should fix the problem. Also you should check if you are getting success status from API.
Related
I have implemented the Google API in PHP as a service and using the Google_Service_ServicePeople() to add a contact. That works and I am getting back a proper result as a paople object. In addition when I call the people_connections->listPeopleConnections method I am getting back the contacts that I have created in my tests. However, when I go to contacts.google.com no contact will be shown.
Maybe it is a missunderstanding from my site, but I thought that based on the appsettings on my account, the new contacts will be created (added) to my account, won't they?
$client = new Google_Client();
$client->setApplicationName ('VABS-CONTACT-TEST');
$client->setAuthConfig($_SERVER['DOCUMENT_ROOT'].'/includes/classes/Google/auth.json');
$client->addScope (Google_Service_Peopleservice::CONTACTS);
$peopleService = new Google_Service_PeopleService($client);
$person = new Google_Service_PeopleService_Person();
$name = new Google_Service_People_Name();
$name->setDisplayName ('FirstName LastName');
$name->setFamilyName ('LastName');
$name->setGivenName('FirstName');
$email = new Google_Service_People_EmailAddress();
$email->value = 'xxx#xxx.xx';
$person->setNames ($name);
$person->setEmailAddresses ($email);
$result = $peopleService->people->createContact ($person);
The response looks like:
Google_Service_PeopleService_Person Object
(
[collection_key:protected] => userDefined
[addressesType:protected] => Google_Service_PeopleService_Address
[addressesDataType:protected] => array
[ageRange] =>
[ageRangesType:protected] => Google_Service_PeopleService_AgeRangeType
[ageRangesDataType:protected] => array
[biographiesType:protected] => Google_Service_PeopleService_Biography
[biographiesDataType:protected] => array
[birthdaysType:protected] => Google_Service_PeopleService_Birthday
[birthdaysDataType:protected] => array
[braggingRightsType:protected] => Google_Service_PeopleService_BraggingRights
[braggingRightsDataType:protected] => array
[coverPhotosType:protected] => Google_Service_PeopleService_CoverPhoto
[coverPhotosDataType:protected] => array
[emailAddressesType:protected] => Google_Service_PeopleService_EmailAddress
[emailAddressesDataType:protected] => array
[etag] => %Eh8BAgMEBQYHCAkKCwwNDg8QERITFBUWFzUZNDciJScuGgwBAgMEBQYHCAkKCwwiDFFrVXd2SnRpTFZZPQ==
[eventsType:protected] => Google_Service_PeopleService_Event
[eventsDataType:protected] => array
[gendersType:protected] => Google_Service_PeopleService_Gender
.
.
.
.
(
)
[modelData:protected] => Array
(
[metadata] => Array
(
[sources] => Array
(
[0] => Array
(
[type] => CONTACT
[id] => 494c65970e1a12eb
[etag] => #QkUwvJtiLVY=
[updateTime] => 2018-04-04T13:58:27.710001Z
)
...
Using the
$peopleService->people_connections->listPeopleConnections('people/me',$options)
lists all the created contacts as expected.
But on my contacts.google.com page no contact will be shown. I am logged in as the same user I have created and granted access to the API.
Any ideas, hwy the contacts won't be shonw on contacts.google.com?
Many thanks!
After several tries it wasn't possible for me to get it solved. Therefore I have tried it now via the RapidWeb Solution. Now it is working and "the setup" with a guide - even though it tooks also 3 steps of getting the right account in place - is simple.
The main problem I had is to understand the logfic of OAuth2 and their possibilities to setup the correct OAuth2 Client.
In my case I needed to setup a Native Client (just choose "Other" as ApplicationType on the second screen in the Google API Console after creating a new OAuth2 ClientId)
Anyway. Many thanks for all who tried to help me! Much appreciated!
Cheers!
I get this error when I try to view the error messages from the API. The documentation says it returns an array of BatchError objects in the PartialError field. When I try to access the Index property of BatchError, it gives me an error. What is wrong?
https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-addadgroups.aspx#Anchor_1
PHP Notice – yii\base\ErrorException
Trying to get property of non-object
1. in /cygdrive/c/Users/Chloe/workspace/bestsales/models/BingAds.php at line 384
$response = $campaignProxy->GetService()->AddAdGroups($request);
} catch (\SoapFault $e) {
$this->handleException($e);
return null;
}
$adGroupsIds = $response->AdGroupIds;
$partialErrors = $response->PartialErrors;
foreach ($partialErrors as $batchError) {
Yii::error($batchError);
$adGroup = $adGroups[$batchError->Index]; # <<<<
Logs:
2016-09-11 22:15:59 [::1][1][v5adqit0fiae7bon3i1lks49m3][error][application] [
unserialize('O:8:"stdClass":8:{s:4:"Code";i:1016;s:7:"Details";N;s:9:"ErrorCode";s:33:"CampaignServiceInvalidEntityState";s:9:"FieldPath";N;s:23:"ForwardCompatibilityMap";N;s:5:"Index";i:0;s:7:"Message";s:104:"Passed entity state is invalid. Please refer to documentation for list of valid values for given entity.";s:4:"Type";s:10:"BatchError";}'),
]
in /cygdrive/c/Users/Chloe/workspace/bestsales/models/BingAds.php:383
in /cygdrive/c/Users/Chloe/workspace/bestsales/models/AdGroup.php:195
in /cygdrive/c/Users/Chloe/workspace/bestsales/models/Keyword.php:145
2016-09-11 22:15:59 [::1][1][v5adqit0fiae7bon3i1lks49m3][error][yii\base\ErrorException:8] exception 'yii\base\ErrorException' with message 'Trying to get property of non-object' in /cygdrive/c/Users/Chloe/workspace/bestsales/models/BingAds.php:384
I also tried
Yii::error($batchError);
Yii::error($batchError['Index']);
Yii::error($batchError::$Index);
Yii::error($batchError->$Index);
Yii::error($batchError->Index);
I used VarDumper and got this:
[
0 => stdClass#1
(
[Code] => 1016
[Details] => null
[ErrorCode] => 'CampaignServiceInvalidEntityState'
[FieldPath] => null
[ForwardCompatibilityMap] => null
[Index] => 0
[Message] => 'Passed entity state is invalid. Please refer to documentation for list of valid values for given entity.'
[Type] => 'BatchError'
)
]
I was able to fix it with
$partialErrors = $response->PartialErrors;
if (!empty($partialErrors->BatchError)) $partialErrors = $partialErrors->BatchError;
foreach ($partialErrors as $batchError) {
Apparently foreach is able to loop over the properties of an object too, which I did know know it could do, and apparently PartialErrors is an object with one property named BatchError which then contains an array (but BatchError may also not exist at all). This doesn't match the documentation, or at least not the documentation of least surprise.
Hello i want to find open houses property using PHP RETS script. i have did below code in which i am able to find Open Houses Property details like MLS_Number,From-date,To time but i am not able to get based on MLS_Number find property other details like address,price,room No and other details. what i have tried so far below is code.
$retsFilters['IS_ACTIVE '] = true;
$retsQuery = '';
foreach ($retsFilters as $key => $value) $retsQuery .= ',('.$key.'='.$value.')';
$retsQuery = trim($retsQuery, ',');
$result = $rets->SearchQuery("openhouse", "OpenHouse",$retsQuery,array('Format' => QUERY_FORMAT));
from above code returns only
Array
(
[AdvertOpenHouse] => 1
[Agent_MUI] => 2871
[Description] =>
[FromDate] => 2016-09-01T00:00:00.000
[FromTime] => 1400
[InputDate] =>
[IS_ACTIVE] => 1
[IsDeleted] => 0
[Listing_MUI] => 9985949
[listing_type] => RE
[matrix_unique_ID] => 10268565
[mls_number] => 548766
[ModificationTimestamp] => 2016-01-08T13:31:23.390
[Open_House_Refreshments] =>
[ToTime] => 1600
)
but i want also more property's details like address,streetName,city,price and other details.
this is the my login url http://rets.saskmls.ca/rets/login.ashx
if any one have idea please help thanks in advance.
Well the Openhouse Resource and underlying classes would not contain this kind of information. There should be a Property Resource with many different kinds of property classes within (Residential, Commercial, Land, etc...)
You need to examine the metadata from the RETS server, it will contain XML that describes all the available Resources, Classes and fields.
Note the signature of the SearchQuery method:
SearchQuery ( string $resource, string $class, string $query [, array $options] )
Your resulting query would look something like this:
SearchQuery("Property", "RES", "(Status=|A)")
I am using Paragon as a MLS back-end provider. When I get an "OpenHouse" resource, there's a field called
L_DisplayId
which is present in "Property" resources.
This field makes a relationship between the two resources.
Once you know L_DisplayId value from an open house, you can search for a property sending L_DisplayId as a search parameter.
Hope that can help you.
I'm having a problem getting a particular SOAP call to work -most of them work fine, but this one is giving me a headache.
The WSDL is http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl, and the request I am generating is:
$result = $soap->checkConnectivity(
array('checkConnectivityRequest' =>
array(
'requestType' => 'SITE',
'requestMode' => array(
'requestId' => date("Ymdhis"),
'siteAddress' => array(
'postalZipCode' => $this->postcode,
'connectivityType' => 'COLT FIBRE',
'bandwidth' => '2M',
),
)
)
)
);
However I'm getting a SOAP error back (which I believe means it's not even passing it to the web service), so not sure if I'm mis-reading the WSDL?
Thanks!
If you search in the content of http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl you will notice that there is not wsdl:operation named checkConnectivityRequest. The closest i saw was checkConnectivity so, try to replace checkConnectivityRequest with checkConnectivity and let me know.
Happy coding
i m trying to to get the request values of form in zend framework
earlier i was using the post method
but the the iphone app is sending me data in get method .
how do i can use it has i was using the post values like
$post = array(
'id'=>'2',
'email'=>'4',
)
i want to get values also in this form value when a form is submitted .
i was using this to get post values
$post = $this->getRequest ()->getPost ();
and i tried this to get get method values
$post = $this->getRequest();
but
i get this error
Cannot use object of type Zend_Controller_Request_Http as array in
this is the full error message
"Zend_Controller_Request_Http Object ( [_paramSources:protected] =>
Array ( [0] => _GET [1] => _POST ) [_requestUri:protected] =>
/platinum-picks/p-picks/index/registration [_baseUrl:protected] =>
/platinum-picks/p-picks [_basePath:protected] => [_pathInfo:protected]
=> /index/registration [_params:protected] => Array ( [controller] => index [action] => registration [module] => default )
[_rawBody:protected] => [_aliases:protected] => Array ( )
[_dispatched:protected] => 1 [_module:protected] => default
[_moduleKey:protected] => module [_controller:protected] => index
[_controllerKey:protected] => controller [_action:protected] =>
registration [_actionKey:protected] => action ) Fatal error: Cannot
use object of type Zend_Controller_Request_Http as array in D:\Program
Files\Zend\Apache2\htdocs\platinum-picks\application\models\User.php
on line 267"
If I understand correctly, you want to get the values passed using GET method and you have done the same successfully with POST values. The only change you need to make in such a scenario is this:
$post = $this->getRequest()->getPost ();
becomes
$get = $this->getRequest()->getParams();
This will also return parameters from other sources:
Retrieves a merged array of parameters, with precedence of userland params (see setParam()), $_GET, $_POST (i.e., values in the userland params will take precedence over all others).
So refer to the manual if this may be a problem for you.
You can find the GET variables using for example:
$this->getRequest()->getParams();
Or, for a specific variable:
$this->getRequest()->getParam('myVar');
This will also search for POST values. To search the GET vars only, use:
$this->getRequest()->getQuery('myVar');