cvent soap api error (php) - php

I'm trying to use php to get access to the Cvent soap API to display a list of upcoming events. I found this: https://github.com/gcanivet/php-cvent
I'm getting "INVALID_CVENT_HEADER_VALUE" when it comes to this function:
public function SearchByFilter($objecttype, $type, $filters){
$response = $this->client->Search((object) array('ObjectType' => $objecttype, 'CvSearchObject' => (object) array('SearchType' => $type, 'Filter' => $filters)));
return $response;
}
I've echoed out what's being sent to that function:
$objecttype = 'Event';
$type = 'AndSearch';
$filters =
Array
(
[0] => stdClass Object
(
[Field] => EventStartDate
[Operator] => Greater than
[Value] => 2016-11-28T00:00:00
)
)
All I've done is save the file, add my credentials and attempted to echo out $events
$account = /* my account */
$username = /* my username */
$password = /* my password */
require('/templates/home/assets/CventClient.class.php');
$cc = new CventClient();
$cc->Login($account,$username,$password);
$events = $cc->GetUpcomingEvents();
I've found this documentation https://custom.cvent.com/5A44061C587B4DF999B70EC98DCA9A84/files/eb1d01535a124863a290b36fa4cd8bd3.pdf but I'm not sure what's wrong, or why it's not working. I have had no experience with SOAP whatsoever. Any help would be greatly appreciated!!

The returned result when you var_dump($event) is the keys of the event. To get the title of the event you have to get the eventId.
`require('/templates/home/assets/CventClient.class.php');
$cc = new CventClient();
$cc->Login($account,$username,$password);
$events = $cc->GetUpcomingEvents();
foreach($events as $event)
{
$response = $cc->GetEventById($event);
//This retrieves the title of all events
$eventsTitle = $response->EventTitle;
var_dump($eventsTitle );
}`

Related

Laravel php How to return response with certain parameters in JSON format

When i received the message in json format as below:
{
"Details":{
"Type":"Cash",
"Payid":"PAY123456",
"Amount":"9000,00",
"Status":"Successful",
}
}
I need to return response in the following JSON format with two parameters only (Type & Payid) that received
{
"Details": {
"Type": "Cash",
"Payid": "PAY123456"
}
}
Currently in my controller it will return the whole details that received.
But how do I modified it, so that it will just return the certain parameters.
public function returnResponse(Request $request)
{
$datas= $request->getContent();
$returnData= json_decode($datas, true);
return response()->json($returnData);
}
This is one way to do it:
public function returnResponse(Request $request){
$datas = $request->getContent();
$parsedJson = json_decode($datas, true);
$returnData = array('Details' => array(
'Type' => $parsedJson['Details']['Payid'],
'Payid' => $parsedJson['Details']['Payid'],
'Confirmation' => 0 // do the same in this line if you want to add more
));
return response()->json($returnData);
}
This code assumes you'll always have 'Type' and 'Payid' inside 'Details'.
The result will be:
Array
(
[Details] => Array
(
[Type] => PAY123456
[Payid] => PAY123456
[Confirmation] => 0
)
)
Note, if you just want to add Confirmation to the original array, you can use:
$returnData['Details']['Confirmation'] = 0;

Google cloud -speech api return null result

I work with Google cloud speech API. When I run my script there is a call to the API and a response. The operation info returns data, but the result is empty.
Here is my code (where file url, file name, key url, project name and bucket name I deleted the real data):
function __construct(){
$file_url='file path.mp3';
$filename='file name.mp3';
/** Create google client **/
$client = new Google_Client();
$key='path to google key';
putenv($key);
$client->useApplicationDefaultCredentials();
/** Create storage **/
$str_config = array(
'projectId' => 'project id'
);
$storage = new StorageClient($str_config);
$bucket_name='bucket name';
$bucket=$storage->bucket($bucket_name);
$object = $bucket->object($filename);
/** Create Speech **/
$config = array(
'projectId' => 'project id',
'languageCode' => 'en-US'
);
$options = array(
"encoding"=>'LINEAR16',
"languageCode"=>"en-US",
'sampleRateHertz' => 16000
)
;
$speech = new Google\Cloud\Speech\SpeechClient($config);
$operation = $speech->beginRecognizeOperation(
$object,
$options
);
$backoff = new ExponentialBackoff(100);
$backoff->execute(function () use ($operation) {
print('Waiting for operation to complete' . PHP_EOL);
$operation->reload();
if (!$operation->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
if ($operation->isComplete()) {
if (empty($results = $operation->results())) {
$results = $operation->info();
}
var_dump($results, $operatimon->results());
}
}
The result i get call:
Array
(
[0] => Array
(
[name] => some name
[metadata] => Array
(
[#type]=> type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeMetadata
[progressPercent] => 100
[startTime] => 2017-07-16T19:15:58.768490Z
[lastUpdateTime] => 2017-07-16T19:15:59.999625Z
)
[done] => 1
[response] => Array
(
[#type]=> type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeResponse
[totalBilledTime] => 15s
)
)
[1] => Array
(
)
)
I tried several file type whit several encodings, can't find the right combination. Or maybe there is another problem. Pleas Help.
Solved it by using the ffmpeg library to encode the audio to flac whit mono channel.
For anyone else encountering this problem, the issue could lie in your audio file not matching the encoding you've entered in your option array.
Check this resource:
https://cloud.google.com/speech-to-text/docs/reference/rest/v1beta1/RecognitionConfig#AudioEncoding
Just like the accepted answer, by changing from "LINEAR16" to "FLAC" and converting my audio file to FLAC, it worked for me.

Google Calendar - trouble with setting Google_EventReminders

I am trying to set a reminder in a calendar using the Google PHP libraries with this code:
$rem = new Google_EventReminders();
$rem->setUseDefault('false');
$overrides = array("method"=> "popup","minutes" => "15");
$rem->setOverrides($overrides);
$event->setReminders($rem);
The event I am sending to the API contains the following data:
[reminders] => Google_EventReminders Object
(
[__overridesType:protected] => Google_EventReminder
[__overridesDataType:protected] => array
[overrides] => Array
(
[method] => popup
[minutes] => 15
)
[useDefault] => false
)
But the event itself does not appear in my calendar with a reminder.
Any pointers on what I'm doing wrong v.gratefully received. Thank you, Tony
You have to pass an array of reminders in the setReminders method, as in this example:
<?php
$reminder = new Google_EventReminders();
$reminder->setUseDefault(false);
$overrides = array("method"=> "popup","minutes" => "15");
$reminder->setOverrides(array($overrides));
$event->setReminders($reminder);
?>
In Google_EventReminders class, the method setOverrides only accepts an array of reminders to validate these settings (by the method assertIsArray), as shown below:
<?php
public function setOverrides(/* array(Google_EventReminder) */ $overrides) {
$this->assertIsArray($overrides, 'Google_EventReminder', __METHOD__);
$this->overrides = $overrides;
}
?>

Twitter OAuth: users/search works but search/tweets does not

I want search for tweets in twitter. It is not working.
$parameters = array('q' => 'oauth');
$result = $connection->get('search', $parameters);
But when I do a user search it working perfectly.
$parameters = array('q' => 'oauth');
$result = $connection->get('users/search', $parameters);
I have also tried the below and that is also not working
$parameters = array('q' => 'oauth');
$result = $connection->get('search/tweets', $parameters);
What could be the reason?
Error message
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Sorry, that page does not exist
[code] => 34
)
)
)
You seem to be using the library TwitterOAuth by Abraham Williams.
I know this is an old question but I have just had the same problem as OP and it might keep happening to anyone else since apparently this library has not been updated for a while.
The problem seems to be that Twitter is no longer accepting requests via the version 1 of their API. You have to change the $host variable in the file twitteroauth.php as follows:
/* Set up the API root URL. */
//public $host = "https://api.twitter.com/1/";
public $host = "https://api.twitter.com/1.1/";

Yahoo Answers API + php Scraper

I have found a php script that would in theorie match my needs, however I cant get it to work and I was wondering if maybe the script is outdated or if I am doing something wrong.
The script looks like this:
<?php
/**
* #package Yahoo Answer
* #author The HungryCoder
* #link http://hungrycoder.xenexbd.com/?p=953
* #version 1.0
* #license GPL, This class does not come with any expressed or implied warranties! Use at your own risks!
*/
class yahooAnswer{
var $appID;
var $searchQuestionURL = 'http://answers.yahooapis.com/AnswersService/V1/questionSearch?';
var $getQuestionURL = 'http://answers.yahooapis.com/AnswersService/V1/getQuestion?';
private $numResults = 10;
private $numStart = 0;
function __construct($appid) {
$this->appID=$appid;
}
function set_numResults($num_results){
$this->numResults = $num_results;
}
/**
* Search for questions for the given keywords. Returned results can be associative array or XML
* #param <string> $kewyord
* #return <string> Returns the results set either in XML format or associative array.
*/
function search_questions($params){
if(!is_array($params)){
throw new Exception('The parameters must be an array!');
}
$defaults = array(
'search_in' => '',
'category_name' => '',
'date_range' => '', //7, 7-30, 30-60, 60-90, more90
'sort' => 'relevance', //relevance, date_desc, date_asc
'type' => 'all',
'output' => 'php',
'results' => $this->numResults,
'start' => $this->numStart,
'region' => 'us',
'appid' => $this->appID,
);
$params = array_merge($defaults,$params);
if(!$params['appid']){
throw new Exception('APP ID is empty!', 404);
}
if(!$params['query']) {
throw new Exception('Query is not set!', '404');
}
$req_params = $this->array2query_string($params);
$url = $this->searchQuestionURL.$req_params;
$results = $this->make_call($url);
if($params['output']=='php'){
$results = unserialize($results);
return $results['Questions'];
}
return $results;
}
/**
* Get all answers of a given question ID
* #param <array> $params keys are: question_id, output, appid
* #return <string> Returns all answers in expected format. default format is php array
*/
function get_question($params){
if(!is_array($params)){
throw new Exception('The parameter must be an array!');
}
$defaults = array(
'question_id' => '',
'output' => 'php',
'appid' => $this->appID,
);
$params = array_merge($defaults,$params);
if(!$params['appid']){
throw new Exception('APP ID is empty!', 404);
}
if(!$params['question_id']) {
throw new Exception('Question ID is not set!', '404');
}
$req_params = $this->array2query_string($params);
$url = $this->getQuestionURL.$req_params;
$results = $this->make_call($url);
if($params['output']=='php'){
$results = unserialize($results);
return $results['Questions'][0];
}
return $results;
}
protected function make_call($url){
if(function_exists('curl_init')){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
$result = curl_exec($ch);
curl_close($ch);
return $result;
} else if(function_exists('file_get_contents')) {
return file_get_contents($url);
} else {
throw new Exception('No method available to contact remote server! We must need cURL or file_get_contents()!', '500');
}
}
protected function array2query_string($array){
if(!is_array($array)) throw new Exception('Parameter must be an array', '500');
$params ='';
foreach($array as $key=>$val){
$params .= "$key=$val&";
}
return $params;
}
}
$appid = 'MYAPPID';
$params = array(
'query' => 'test', //enter your keyword here. this will be searched on yahoo answer
'results' => 2, //number of questions it should return
'type' => 'resolved', //only resolved questiosn will be returned. other values can be all, open, undecided
'output' => 'php', //result will be PHP array. Other values can be xml, json, rss
);
$question_id = 'test'; //without this i get an error "Question ID is not set!"
$yn = new yahooAnswer($appid);
//search questions
try{
$questions = $yn->search_questions($params);
} catch (Exception $e){
echo ($e->getMessage());
}
foreach ($questions as $question) {
//now get the answers for the question_id;
try{
$answers = $yn->get_question(array('question_id'=>$question_id));
echo '<pre>';
print_r($answers);
echo '<pre>';
} catch (Exception $e){
echo($e->getMessage());
}
}
?>
But instead of a valid output I just get this:
Array
(
[id] =>
[type] =>
[Subject] =>
[Content] =>
[Date] =>
[Timestamp] =>
[Link] => http://answers.yahoo.com/question/?qid=
[Category] => Array
(
[id] =>
[content] =>
)
[UserId] =>
[UserNick] =>
[UserPhotoURL] =>
[NumAnswers] =>
[NumComments] =>
[ChosenAnswer] =>
[ChosenAnswererId] =>
[ChosenAnswererNick] =>
[ChosenAnswerTimestamp] =>
[ChosenAnswerAwardTimestamp] =>
)
I have tried it with other keywords, but the result is always the same.
This part $question_id = 'test'; is not included in the official script, but without it I keep getting Question ID is not set!.
I also tried to change it, add it at another place in the script etc. Everything I could think of, but the result was always that array with no information besides the [Link]
Since I got almost zero php experience at all, I am not even where start looking for an error :/ Would be glad if some1 could point me in the right direction!
Regards!
p.s. of course "MYAPPID" is changed to my real yahoo app id.
In order to make this example work, change this line:
$answers = $yn->get_question(array('question_id'=>$question_id));
to:
$answers = $yn->get_question(array('question_id'=>$question['id']));
That change pulls the actual question ID out of the response from search_questions(), and uses it in the call to get_question().

Categories