PHP5 and Microsoft Live Search 2.0 - php

I'm trying to use Live Search 2.0 but even a simple example doesn't seem to work. Microsoft only has example code for 1.1 and they're not giving out AppIDs for that version.
Here's what I'm trying with:
<?php
$server = new SoapClient('http://soap.search.msn.com/webservices.asmx?wsdl');
class Search {
public $Request;
}
class SearchRequest {
public $AppID;
public $Query;
public $CultureInfo;
public $SafeSearch;
public $Flags;
public $Location;
public $Requests;
}
class SourceRequest {
public $Source;
public $Offset;
public $Count;
public $FileType;
public $SortBy;
public $ResultFields;
public $SearchTagFilters;
}
$searchRequest = new SourceRequest();
$searchRequest->Source = 'Web';
$searchRequest->Offset = 0;
$searchRequest->Count = 5;
$searchRequest->ResultFields = 'All SearchTagsArray';
$request = new SearchRequest();
$request->AppID = '...';
$request->Query = 'Bill Gates';
$request->CultureInfo = 'en-US';
$request->SafeSearch = 'Off';
$request->Flags = '';
$request->Requests = array($searchRequest);
$search = new Search();
$search->Request = $request;
$server->Search($search);
?>
AppID is correctly specified in the code: I just erased it from here. I'm getting the following error:
Array ( [0] => SearchResponse Search(Search $parameters) )
Fatal error: Uncaught SoapFault exception: [soapenv:Client] Client Error in /Users/thardas/Sites/vt9/widgets/ms_livesearch.php:41
Stack trace:
#0 [internal function]: SoapClient->__call('Search', Array)
#1 /Users/thardas/Sites/vt9/widgets/ms_livesearch.php(41): SoapClient->Search(Object(SearchRequest))
#2 /Users/thardas/Sites/vt9/index.php(23): include('/Users/thardas/...')
#3 {main} thrown in /Users/thardas/Sites/vt9/widgets/ms_livesearch.php on line 41

You could begin by using the proper soap api url for 2.0.
It's now
"http://api.search.live.net/search.wsdl?AppID=YourAppId" taken from (http://msdn.microsoft.com/en-us/library/dd250965.aspx )
You can also use the new JSON api with php.
$appid = 'Your app id';
$searchitem = 'PHP Manual';
$request = 'http://api.search.live.net/json.aspx?Appid=' . $appid . '&sources=web&query=' . urlencode( $searchitem);
$response = file_get_contents($request);
$jsonobj = json_decode($response);
foreach($jsonobj->SearchResponse->Web->Results as $value)
{
//$value->Url
//$value->Title
//$value->Description
}
And finally theres a xml api you can look up at the msdn link as well and it can be fetched essentially the same way as the json you just need to decode it differently.

The sample code for API 2.0 is on MSDN but we do not have the complete PHP code sample out yet.
A first code sample (very similar to the one in the answer you already got) in included in the blog post on the Live Search Developer Blog
You may be aware that there are currently some issues with SOAP in PHP 5.2.6 - the Live Search service seems to be affected by it in both 1.1 and 2.0. The simplest workaround is to use another interface (JSON or XML)

Related

This happens only on live server: Fatal error: Uncaught Error: Call to a member function signin() on boolean in

Confession:
I read many similar questions on this platform, but nothing seems closely aligned to my situation. Most of the questions seem to originate from binding params in prepared statements or execute statement.
In my case, the website runs smooth on a local server(Apache2). However, it throws the error below when published on live server.
Fatal error: Uncaught Error: Call to a member function signin() on boolean in /storage/ssd5/815/17670815/app/controllers/signin.php:16 Stack trace: #0 /storage/ssd5/815/17670815/app/core/app.php(33): Signin->index() #1 /storage/ssd5/815/17670815/public_html/index.php(4): App->__construct() #2 {main} thrown in /storage/ssd5/815/17670815/app/controllers/signin.php on line 16
Context
I'm using MVC (OOP) in PHP and here the relevant parts mentioned in the error. I hope this is not too much.
In the main index page, the line referred in the error is a core class(App) instantiation
<?php
session_start();
require_once '../app/initializer.php';
$app = new App(); //this is the line 4 mentioned in the error
In Signin controller class the line referred in the error is indicated below
<?php
class Signin extends Controller{
function index(){
//you can do this if passing data to view
$data["Page_title"] = "Signin";
if($_SERVER['REQUEST_METHOD'] == "POST"){
// this is a debuggin code
//echo "I am signin controller <br />";
// show($_POST);
$user = $this->loadModel("User");
$user->signin($_POST); //this the line referred in the error
}
$this->view("zac/signin",$data);
}
}
In class APP the line is a callback - check below
<?php
class App {
private $controller = "home";
private $method = "index";
private $params = [];
public function __construct()
{
$url = $this->splitURL();
if(file_exists("../app/controllers/".strtolower($url[0]).".php")){
$this->controller = strtolower($url[0]);
//unset the array position
unset($url[0]);
}
require "../app/controllers/".$this->controller.".php";
// echo file_get_contents('http://smart-ecom.000webhostapp.com/app/controllers/'.$this->controller.".php");
//Create instance of whatever controller class is passed(if it exists, otherwise the home controller)
$this->controller = new $this->controller;
if(isset($url[1])){
if(method_exists($this->controller, $url[1])){
$this->method =$url[1];
unset($url[1]);
}
}
$this->params = array_values($url);
call_user_func_array([$this->controller, $this->method],$this->params); //this is line 33
}
/**
* splitURL gets url from browser and processes against the conroller classes and their methods
* #return array
*/
private function splitURL(){
//check if the the GET is set otherwise set the url to defualt class home
$url = isset($_GET['url']) ? $_GET['url'] :"home";
// return explode("/",filter_var(trim($_GET['url'],"/"), FILTER_SANITIZE_URL));
return explode("/",filter_var(trim($url,"/"), FILTER_SANITIZE_URL));
}
}
?>
The Database class's read function is as follows. This method isn't directly referred in the error message
public function read($query, $data = []){
$stmt = self::$conn->prepare($query);
$result = $stmt->execute($data);
if($result){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(is_array($data) && count($data) > 0){
return $data;
}
}
return false;
}
As I mentioned earlier, this error fires on a live server but the website runs smooth in dev environment with PHP 7.4, Apache2, MySQL 8 Windows 10.
Your help is match appreciated in advance.
I learned this the hard way and I hope this can help someone with similar issues. The cause of the error because of how windows and Linux deals with case sensitivity in file names. In Windows, file names aren't case sensitive while in Linux - they are. So, that was the reason why the website was running smooth in the local dev environment(Windows machine) but throwing an error on a live server(which is Linux). To see the difference, refer to my earlier comment in this thread.
protected function loadModel($model){
if(file_exists("../app/models/". strtolower($model) . ".class.php")){
include "../app/models/".strtolower($model).".class.php";
return $model = new $model();
}else{
return false;
}
}
}
In the "include" line, you can see that I added the strtolower function to include the proper model and that solved the issue.

PHP Error, class not found

I'm getting the following output on my page when I go to Test.php:
longitude = $long;
$this->latitude = $lat;
}
public function getgeo(){
require_once('lib/mapbox/MapBox.php');
$request = new MapBox('redacted');
$request = $request->reverseGeocode($this->longitude,$this->latitude);
$request = explode(', ',$request[0]['place_name']);
if(count($request)>3){
array_shift($request);
array_splice($request,2,1);
}
$return = array($request[0],$request[2]);
}
}
?>
Fatal error: Uncaught Error: Class 'ReverseGeo' not found in /var/www/html/api.redacted.com/public_html/test.php:8 Stack trace: #0 {main} thrown in /var/www/html/api.redacted.com/public_html/test.php on line 8
Test.php
<?php
require_once(__dir__ . '/classes/reversegeo.php');
$long = '-73.988909';
$lat = '40.733122';
$reversegeo = new ReverseGeo($long, $lat);
$return = $reversegeo->getgeo();
var_dump($return);
?>
classes/reversegeo.php
Class ReverseGeo{
protected $longitude;
protected $latitude;
public function __construct($long, $lat){
$this->longitude = $long;
$this->latitude = $lat;
}
public function getgeo(){
require_once('lib/mapbox/MapBox.php');
$request = new MapBox('redacted');
$request = $request->reverseGeocode($this->longitude,$this->latitude);
$request = explode(', ',$request[0]['place_name']);
if(count($request)>3){
array_shift($request);
array_splice($request,2,1);
}
$return = array($request[0],$request[2]);
}
}
I've confirmed that directories are all correct, file names are correct, etc. and I'm not sure whats going on with this.
Per our discussion in chat, as your php does not support the short opening tag you need to use the full opener. The short tag is the reason that your php source code gets sent directly to the browser and not to the php engine.
You can configure your php settings to allow the short opening tag but its not recommended for portability reasons.
<? should be changed to <?php
As a side note later versions of php no longer need the closing tag at the end of the file so that can be removed if your php supports it.

Integrate MyAllocator SDK with zf2

I have been looking for the help to configure SDK for my Allocator.
I have already followed the steps given in the documentation.
https://github.com/MyAllocator/myallocator-ota-php
From the above documentation I have installed myAllocator using composer and I can see MyAllocator directory inside vendor.
Moving further I tried to copy the code from MaReceiver.php to my controller but this does not work out.
I have also checked how to configure the facebook sdk but this also does not help me to get a good idea to work out with MyAllocator SDK.
Again now tried to created a separate module in zf2 but I did not get any success.
It would be really helpful if anyone can guide me of give me any reference for SDK configuration in zend framework 2.
Please find the code
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost('id');
$propertyId = $request->getPost('pand_id');
$password = $data['pand_password'];
$guid = empty($data['guid'])? '' : $data['guid'];
$verb = empty($data['verb'])? 'SetupProperty' : $data['verb'];
$booking_id = empty($data['booking_id'])? '' : $data['booking_id'];
$myallocator_pid = empty($data['pid'])? '' : $data['pid'];
// Instantiate backend interface that implements MaInboundInterface
$interface = new MaInboundInterfaceStub();
$interface->mya_property_id = $myallocator_pid;
$interface->ota_property_id = $propertyId;
$interface->verb = $verb;
$interface->guid = $guid;
$interface->shared_secret = 'xxxx';
$interface->ota_regcode = $password;
$interface->booking_id = $booking_id;
$interface->mya_property_id = 'M not in else ';
$router = new \MyAllocator\phpsdkota\src\Api\Inbound\MaRouter($interface);
// Process request
$post_body = file_get_contents('php://input');
$post_body = json_encode($interface);
$response = $router->processRequest($post_body);
header('Content-Type: application/json');
echo json_encode($response);exit;
}
With the above code am successfully able to call the function and work perfectly fine with the value on interface object
But now the problem is that am not able to get the request parameter from MyAllocator

Get all task from project using Asana API in php

I have to fetch task using Asana API under project,
I tried so far but gives error
$tasksall = $asana->getProjectTasks($projectId);
$tasksJson = json_decode($tasksall);
print_r($taskJson);
Call a function
public function getProjectTasks($projectId){
return $this->askAsana($this->taskUrl."?project={$projectId}");
}
Try this..
Use this as your main part
$projectId='Your project id';
$taskbyproject = $asana->getProjectTasks($projectId);
//print_r($taskbyproject);
Use this as Function
public function getProjectTasks($projectId, array $opts = array())
{
$options = http_build_query($opts);
return $this->askAsana($this->taskUrl . '?project=' . $projectId . '&' . $options);
}

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://127.0.0.1/test/index?wsdl' :

I get a problem when I use the SOAP component in zend framework 2.0
The following is the code :
namespace User\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\Server;
use Zend\Soap\Client;
use Zend\Soap\AutoDiscover;
use User\Model\MyTest;
class TestController extends AbstractActionController {
private $_WSDL_URI = "http://127.0.0.1/test/index?wsdl";
private function handleWSDL() {
$autodiscover = new AutoDiscover();
//ini_set("soap.wsdl_cache_enabled", 0);
$autodiscover->setClass('User\Model\MyTest')
->setUri($this->_WSDL_URI);
$wsdl = $autodiscover->generate();
header("Content-type: text/xml");
echo $wsdl->toXml();
exit;
}
private function handleSOAP() {
$soap = new Server($this->_WSDL_URI,array('encoding' => 'utf-8','soap_version'=>SOAP_1_2));
$soap->setClass('User\Model\MyTest');
$soap->handle();
exit;
}
public function indexAction(){
if(isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
public function clientAction(){
$client = new Client('http://127.0.0.1/test/index?wsdl');
$result = $client->getUser(31);
var_dump($result);exit;
}
}
when I visit http://localhost/test/index?wsdl ,It returns the WSDL.
But when I visit http://localhost/test/index,It returns the error:
SOAP-ERROR: Parsing WSDL: Couldn't load from http://127.0.0.1/test/index?wsdl : failed to load external entity "http://127.0.0.1/test/index?wsdl"
When I visit http://localhost/test/client, It returns
An error occurred
An error occurred during execution; please try again later.
Additional information:
SoapFault
File:
E:\WWW\vendor\ZF2\library\Zend\Soap\Client.php:1087
Message:
Wrong Version
Stack trace:
#0 E:\WWW\vendor\ZF2\library\Zend\Soap\Client.php(1087): SoapClient->__soapCall('getUser', Array, NULL, NULL, Array)
#1 E:\WWW\module\User\src\User\Controller\TestController.php(44): Zend\Soap\Client->__call('getUser', Array)
here is the MyTest.php file
namespace User\Model;
class MyTest{
/**
* To get the register information of the user
*
* #return string
*/
public function getUser(){
return 'hello';
}
}
Thanks in advance.
To create a Soap server, you only need the WSDL file, not the URL that is used to serve it to other clients. In fact, it is better performing NOT to use a URL for this, because every request to the Soap server will start a subrequest to fetch the WSDL.
Try to put the WSDL somewhere once it's created, and fetch it from there on subsequent requests. Autodetecting it every time is only good when doing development without a specified interface. Which will break things once somebody else is using this interface and relies on its stability.

Categories