Issue with Google API People :: AddContact - php

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!

Related

Getting blank response from Google Talent API

I am targeting to load Google Jobs search result in my custom website.
So for that I created account on google and enable Google Talent API. After enable billing on google cloud API account, they allow me request to this API using API Key and Service account credentials.
I am currently using PHP with the use of api-client-php library.
For that I have download .json file for credential (client_secret.json) from google Console Talent Platform.
Here is my sample code in PHP.
require 'vendor/autoload.php';
// Instantiate the client
$client = new Google_Client();
$api_key = 'AdsadsIzaSyBYAMxEPPasdadadw5VHITCdREQW7WYeIGs8jRlUYqlzLM';
$client->setDeveloperKey($api_key);
$client->setAuthConfig(getcwd() . '/client_secret.json');
$client->setScopes(array(
'https://www.googleapis.com/auth/jobs',
'https://www.googleapis.com/auth/cloud-platform'
));
$jobs = new Google_Service_JobService($client);
$location='USA';
// Set the Metadata
$requestMetadata = new Google_Service_JobService_RequestMetadata();
$requestMetadata->setUserId('000aaaa');
$requestMetadata->setSessionId('000aaaa-1212-21212');
$requestMetadata->setDomain('www.google.com');
$jobQuery = new Google_Service_JobService_JobQuery();
$keyword='software OR java';
$jobQuery->setQuery($keyword);
// Search Job Request
$searchRequest = new Google_Service_JobService_SearchJobsRequest();
$searchRequest->setRequestMetadata($requestMetadata);
$searchRequest->setQuery($jobQuery);
$searchRequest->setMode('JOB_SEARCH');
$jobService = new Google_Service_JobService($client);
$response = $jobService->jobs->search($searchRequest);
echo "<pre>";
print_r($response);
print_r($response->matchingJobs);
While sending this request, We are getting matchingjobs blank array but $response have some object array. which is something like not output but just request information.
here is the response which we are getting so far using Talent Search API.
Google_Service_JobService_SearchJobsResponse Object
(
[collection_key:protected] => matchingJobs
[appliedCommuteFilterType:protected] => Google_Service_JobService_CommutePreference
[appliedCommuteFilterDataType:protected] =>
[appliedJobLocationFiltersType:protected] => Google_Service_JobService_JobLocation
[appliedJobLocationFiltersDataType:protected] => array
[estimatedTotalSize] =>
[histogramResultsType:protected] => Google_Service_JobService_HistogramResults
[histogramResultsDataType:protected] =>
[jobView] =>
[matchingJobsType:protected] => Google_Service_JobService_MatchingJob
[matchingJobsDataType:protected] => array
[metadataType:protected] => Google_Service_JobService_ResponseMetadata
[metadataDataType:protected] =>
[nextPageToken] =>
[numJobsFromBroadenedQuery] => 0
[spellResultType:protected] => Google_Service_JobService_SpellingCorrection
[spellResultDataType:protected] =>
[totalSize] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[metadata] => Google_Service_JobService_ResponseMetadata Object
(
[collection_key:protected] => experimentIdList
[experimentIdList] => Array
(
[0] => 11300310
[1] => 11300342
)
[mode] => JOB_SEARCH
[requestId] => f5cacd36-db29-4d65-851f-34a97c98af79:APAb7IRQAVop4QZ6rC2OlKjcEARRJQHI8w==
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
Array
(
)
I am confuse here, Talent API can search and load google Jobs on our website OR we need to create company and jobs and they just provide Advanced search filter using AI and ML ?
Lets if they provide google Jobs on our website then what is wrong in my code ?
Please suggest me.
Google's Talent API only works with data you provide it, so yes, you should create companies and jobs and then apply the searches to those jobs.
The second step in the checklist they've published for launching apps that use this API is Index companies and jobs, with clear mentions of these being from your own database:
Create at least one Company. We recommend creating Company objects for
all companies in your database with open jobs.
Create Jobs for your Companies. We recommend creating Job objects for
all open jobs in your database.
Additional proof that supports this disappointing reality is an article published by Ivan Davchev after the Google conference where this API was announced:
What Is Google Jobs API?
It is a turn-key solution to searching your jobs. Like most cloud-based search > solutions, you need to feed it documents (jobs) which it indexes and makes searchable.
[...]
It is not an aggregator and does not offer “all jobs in the world” out of the box. > So you can’t build an Indeed competitor in an afternoon with this API. It only searches > what you provide it, which is why it makes sense for job boards and applicant tracking > systems (ATS) to use it — jobs are posted on and managed by those systems.

How to get user Activity using aweber api

i am trying to get user activity via aweber rest api using thier aweber php library.
code:
$all_subscribers = $account->findSubscribers($params);
foreach ($all_subscribers as $sub) {
echo "<p><strong>Name:</strong> {$sub->name}</p>";
echo "<p><strong>Email:...;
foreach ($sub->getActivity() as $event) {
echo "<p>{$event->type}: {$event->event_time}</p>";
}
}
i am able to get the details such as event type and event timing but i also need to fetch title and the url of the message on which the events were happened.
i also tried $event->self_link but it was no help.
Here is the data return by getActivity() method
[data] => Array
(
[event_time] => 2017-04-30 07:05:00-04:00
[resource_type_link] => https://api.aweber.com/1.0/#open
[http_etag] => "28eb617e4d24407e49b14a9402608f423da2f4a7-ca5feee2b7fbb6febfca8af5541541ea960aaedb"
[subscriber_link] => https://api.aweber.com/1.0/accounts/1011749/lists/4120909/subscribers/59065294
[self_link] => https://api.aweber.com/1.0/accounts/1011749/lists/4120909/campaigns/f28501689/messages/40127/opens/15096
[type] => open
[id] => 15096
)

IP.Board - Single Sign On in php

I'm developing a small hand made web portal for a community and I want it to have a loggin system with IP.Board (easier for the end user).
I have the forum and the app on the same hosting.
For the loggin, the user clicks on a button and is redirected to this page:
<?php
require_once '../www/forum/init.php';
include_once 'includes/functions.php';
error_reporting(E_ALL);
session_start();
\IPS\Session\Front::i();
print_r( \IPS\Member::loggedIn());
if(\IPS\Member::loggedIn()->member_id) {
$name = \IPS\Member::loggedIn()->name;
if(checkUserExistance($name)==0){
//header("Location: ../index.php");
print("LOGED EXIT!!!!!!!!!!!!!!!!!!!!");
}else{
print("LOGED INNNN!!!!!!!!!!!!!!!!!!!!");
$_SESSION['authenticated'] = 'yes';
$_SESSION['user'] = $name;
$userphoto = \IPS\Member::loggedIn()->photo;
$result = getUserData($_SESSION['user']);
$_SESSION['isLeader'] = $result['isLeader'];
$_SESSION['isAdmin'] = $result['isAdmin'];
}
} else{
print("LOGED OUT!!!!!!!!!!!!!!!!!!!!");
$_SESSION['authenticated'] = 'no';
if(session_destroy()){ // Destroying All Sessions
//header("Location: index.php");
}
}
//echo "Auth by LOGIN";
?>
If is not logged in IP.Board session (forum), it goes back to index.php
For now im developing a basic version of it, more improvements will be done once I get this working.
As you can see I have a print for debuging some data.
On Edge everything works, but on Firefox or chrome I get a string of 32 characters, each time a diferent one, instead of getting the username.
Example of what i get in Firefox and Chrome.
ef5cd2de05387b9b01048efad2173efd
Does any one know why is this?
INFO: I followed: IP.Board SSO Documentation
INFO2: Forum post
I'm using IPS Community Suite as the "Master".
EDIT 1: Debug of \IPS\Member::loggedIn()
IPS\Member Object ( [nodeClass:protected] => IPS\awards\Cats
[_followData] => [_previousPhotoType:protected] => [_group] =>
[restrictions:protected] => [modPermissions:protected] =>
[calculatedLanguageId:protected] => [markers] => Array ( )
[markersResetTimes:protected] => Array ( ) [haveAllMarkers:protected]
=> [defaultStreamId:protected] => [changedCustomFields] => Array ( ) [previousName:protected] => [_socialGroups:protected] =>
[sessionData:protected] => [_lang:protected] => [_url:protected] =>
[profileFields] => [_reputationData:protected] =>
[_following:protected] => Array ( ) [reportCount:protected] =>
[ignorePreferences:protected] => [_ppdLimit:protected] =>
[_data:protected] => Array ( [member_group_id] => 2 [mgroup_others] =>
[joined] => 1483440989 [ip_address] => 83.36.150.111 [timezone] => UTC
[allow_admin_mails] => 1 [pp_photo_type] => [member_posts] => 0
[pp_main_photo] => [pp_thumb_photo] => [failed_logins] =>
[pp_reputation_points] => 0 [signature] => [auto_track] =>
{"content":0,"comments":0,"method":"immediate"} ) [_new:protected] =>
1 [changed] => Array ( [member_group_id] => 2 [mgroup_others] =>
[joined] => 1483440989 [ip_address] => 83.36.150.111 [timezone] => UTC
[allow_admin_mails] => 1 [pp_photo_type] => [member_posts] => 0 )
[skipCloneDuplication] => )
Well I recognise that this is over two years ago now, but I haverecently ran into the same problem using a localhost installation. In my case, when I tried in a blank new file it did the same problem but eventually fixed itself.
When I tried to actually integrate it with my site, it did this every single time. It turned out in my case that it was something to do with stripping bad UTF-8 characters.
I have absolutely no idea why this made any difference, but as soon as I took the code out that was stripping these characters out of GET, POST and most importantly, COOKIE, it started working perfectly.
For anyone doing this now, there's really nothing you can do other than trial and error in commenting out lines of code until you find it. IPS really aren't helpful at all with this kind of thing and leave you feeling like you're on your own with it (which you virtually are).
Make sure the url (domain part) to your system is the same as IPS, ie www.example.com not only example.com
example.com will give that hash, while www.example.com will not.
Spent some time before seeing this....
Edit: and that was not it at all. If I log out of the forum and in, maybe several times, it works in all browsers. I do not see a pattern, except trying several times (at least once). Sorry for poor answer!
Eirik
I decided to use the other option for SSO in IP.Board Te other option, sends the login request to the forum, and does not need to check the sessions. Forum API does it.

CakePHP SoapClient drops fields?

My app uses CakePHP (2.2.5) to get data from a SOAP server. I put logging into the SoapSource.php connector to see the XML returned and to display the array returned:
$result = $this->client->__soapCall($method, array('parameters' => $tParams));
Logger::write('SOAP Last Response', $this->client->__getLastResponse(), 3, 'transaction');
Logger::write('SOAP Last Response Object', print_r($result, TRUE), 3, 'transaction');
But what I'm seeing in the log is that two (recently-added) fields present in the XML are missing from the array, specifically, the last two before the RPList (formatted here but otherwise verbatim):
<transactionResult>
<id>test</id>
<resultCode>0</resultCode>
<ReadScheduledRecordingsRsp>
<RecordingDefinitionList>
<RecordingDefinition>
<RDId>d8c16d8f-67c6-469a-83c3-d51d8f8859a9</RDId>
<Title>The Young and the Restless</Title>
<SeriesId>4422</SeriesId>
<KeepUntil>SpaceIsNeeded</KeepUntil>
<StartPadSeconds>0</StartPadSeconds>
<EndPadSeconds>0</EndPadSeconds>
<Frequency>EveryDay</Frequency>
<KeepAtMost>0</KeepAtMost>
<Priority>23</Priority>
<ShowType>Any</ShowType>
<AirtimeDomain>SpecificTime</AirtimeDomain>
<ChannelDomain>SpecificChannel</ChannelDomain>
<RPList>
...
Followed by:
ARRAY
(
[transactionResult] => stdClass Object
(
[id] => test
[resultCode] => 0
[ReadScheduledRecordingsRsp] => stdClass Object
(
[RecordingDefinitionList] => stdClass Object
(
[RecordingDefinition] => Array
(
[0] => stdClass Object
(
[RDId] => d8c16d8f-67c6-469a-83c3-d51d8f8859a9
[Title] => The Young and the Restless
[SeriesId] => 4422
[KeepUntil] => SpaceIsNeeded
[StartPadSeconds] => 0
[EndPadSeconds] => 0
[Frequency] => EveryDay
[KeepAtMost] => 0
[Priority] => 23
[ShowType] => Any
[RPList] => stdClass Object
(
...
I'm guessing I just forgot or didn't know to do something, but I don't know what. It's just very suspicious that the two fields that don't work are the two that were just added, but I can't find any place where the fields are enumerated.
The WSDL doesn't specify any fields at all, just that there will be a bunch of data inside a transactionResult.
In the connect call, the options likewise don't specify any fields.
It all worked fine until the back-end added those two fields, and it all still works fine, except that I can't see the 2 new fields in the object.
Any ideas?
It would be nice to see the XML for RPList. What version of PHP/libxml?
Have you actually validated the XML returned by __getLastResponse()?
It sounds to me like your using WSDL mode for the client but your WSDL file lacks precision. Try using a WSDL which actually describes the data being served up by the API.
Am I understanding that the $result object when dumped lists RPList but the value is not what you expect? If so you might be able to get away with adding the SOAP_SINGLE_ELEMENT_ARRAYS option to the clients constructor: new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));. That's a long shot though. Need to see WSDL and full output from __getLastResponse().
Any errors? Try wrapping the call like so:
try {
$client = new SoapClient ('http://yoursite.com?WSDL',
array("trace" => 1,
"exceptions" => true,
"cache_wsdl" => WSDL_CACHE_NONE,
"features" => SOAP_SINGLE_ELEMENT_ARRAYS)
);
$result = $client->SomeMethod($data);
} catch (SoapFault $exception) {
var_dump($exception);
} catch (Exception $exception) {
var_dump($exception);
}
Short of fixing the WSDL/XML response your workaround seems like the best solution.

CakePHP 1.3 validation errors not showing with numerical indexed array

I've looked at loads of forums about validation errors not showing and tried various things but to no avail...
Basically, the validation is correctly recognising the fields do not have values when they should, however the error messages don't 'automagically' appear below the input boxes.
Model validation rule is shown below:
var $validate = array(
'description' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a description of the change'
)
);
echo pr($this->data); output is shown below:
Array
(
[Change] => Array
(
[0] => Array
(
[id] => 3237
[cn_id] => 5132
[req_id] => 25
[description] =>
)
[1] => Array
(
[id] => 3238
[cn_id] => 5132
[req_id] => 22
[description] =>
)
[2] => Array
(
[id] => 3239
[cn_id] => 5132
[req_id] => 4
[description] =>
)
)
)
echo pr($this->Change->invalidFields()); output is shown below:
Array
(
[0] => Array
(
[description] => Please enter a description of the change
)
[1] => Array
(
[description] => Please enter a description of the change
)
[2] => Array
(
[description] => Please enter a description of the change
)
[description] => Please enter a description of the change
)
So, it is generating the errors messages for display, but they don't actually display in the view, and I don't know why?
Excerpt from the 'view' code is show below:
<?php echo $form->input('Change.'.$i.'.description',
array('value' => $cn['Change'][$i]['description'],
'label' => $engReq['Req']['description'])); ?>
Does anybody have ideas why the error messages are not showing?
I experienced the same issue with a hasMany model (where the form had numerically indexed fields) and came up with a validation solution that worked for me.
Quick answer: Before trying to actually save the data, I validated the data separately like (notice 'validate'=>'only'):
if($this->ModelName->saveAll($this->data, array('validate' => 'only'))) {
// proceed to save...
}
Doing it this way gave me the model's validation error message in the form, right under the input field that failed the validation (the normal Cake way of showing the validation error).
Note: I could not use saveAll() to actually save my data (I'll explain why in a minute). If I could use saveAll() to actually save the data, I could have gotten the validation at the same time as I saved by using (notice 'validate' => 'first'):
if($this->ModelName->saveAll($this->data, array('validate' => 'first')))
However, I could not use saveAll() to actually save the data, due to the fact that I needed to use a transaction to save several models at once, where some of the models were not directly related to other models. saveAll() will only save the model on which it is called, plus models directly related to it. Since Cake does not currently support nested transactions, and saveAll() uses one transaction automatically, I had to use save() on my models and start and end my transaction manually. However, this caused me to loose the validation message in my form on the hasMany items, even if I saved by using "$this->ModelName->save($this->data, array('validate'=>'first')".
Further explanation: The issue does seem to be related to using numerically indexed fields in the form. For example:
$this->Form->input("ModelName.0.field_name");
It seems this indexing scheme is the proper way to handle hasMany items in the form, but the validation messages would not find their way to this form input. It is interesting to notice that my view did in fact have access to the validation error. This can be seen in the view by using (notice no numerical index in these lines):
if($this->Form->isFieldError("ModelName.field_name")) {
echo $this->Form->error("ModelName.field_name");
}
Putting these lines after the '$this->Form->input("ModelName.0.field_name")' inserted a the validation message into the page, just not in the same div as the input field (and thus it didn't look ideal).
I couldn't figure out a way to tell Cake to use that validation message in the '$this->Form->input("ModelName.0.field_name")'. So I resorted to the 'validate' => 'only' method described earlier, which is working well for me.
shouldnt it be
var $validate = array(
'description' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a description of the change'
)
)
);
?

Categories