xmlrpc getting an error xmpp user register - xmpp

I have working o ejabberd and xmpp but while register user i am getting an error
Notice: xmlrpc: Error -118 A problem '{error,access_rules_unauthorized}' occurred executing the command register with arguments
I am using this code
$request = xmlrpc_encode_request($command, $params, (array('encoding' => 'utf-8')));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($request),
'content' => $request
)));
// echo '<pre>'; print_R($context); die;
$file = file_get_contents('http://192.168.1.22:4560/RPC2', false, $context);
//echo '<pre>'; print_R($file); die;
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
return $response;
}
I have tried everything but still getting an error.

So, you finally solved the previous problem you had in what else to do to enable XML-RPC in ejabberd? ? You can add an explanation there to help other people, or at least mark the problem as solved, so other people don't waste their time investigating something that you no longer care about.

Related

Is there a way to fix a date error using Symfony 4?

I'm working on a project as a back-end developer using PHP 7.2.11 and Symfony 4.2.3
My goal is to showcase events (concerts, festivals...) from data I grab from an API on an interactive map.
This is the result I get:
https://imgur.com/HmpBK5B.png
To import the data from the API, I use a for loop going from 1 to 7 (corresponding to days) and adding days to the today's date.
This date will be used as a parameter to grab the events occuring from today to the next 7 days.
Problem is: I get the following error running my custom symfony command
php bin/console import:mapado :
2019-03-26T12:08:34+01:00 [error] Error thrown while running command "import:mapado". Message: "Notice: Undefined index: address"
The error is due to a date not existing and then refering to an inexistant address.
I tried to change the parameters in my first for loop, with days going either to 8 or to 6 but it didn't change the output error.
I change the custom date parameter (from my loop) from the API url to the default parameter and everything is working with default (but it only gets the events for the 3 next days).
Here is the parameter I use:
https://imgur.com/tx1OyrM.png
From: https://api.mapado.net/v2/docs#operation/getActivityCollection
And how an element from the API looks like:
https://imgur.com/l1nTOCC.png
This is the code I've written:
protected function execute(InputInterface $input, OutputInterface $output) {
for ($jour = 0; $jour <= 7; $jour++) {
// problem is here
$futureDay = date('Y-m-d', strtotime('+'.$jour.' days'));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.mapado.net/v2/activities?fields=#id,title,shortDate,nextDate,activityType,locale,description,address&itemsPerPage=1000&when=".$futureDay."&periodOfDay=evening",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer MTMwZWJiODFiZjA4YTcyOGY2ZmMzMGYwOTQyYWM2NDZjODVlNDg1MzU0MzE3M2I4MTdiMDQyZjU5MDVkZjFjZA",
"Cache-Control: no-cache",
"Conent-Type: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: 55672a19-0ffc-4fe6-a866-3e15c3df9dae"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$mapado_events = json_decode($response, JSON_PRETTY_PRINT);
for ($i = 0; $i < count($mapado_events['hydra:member']); $i++) {
if ($mapado_events['hydra:member'][$i]['locale'] == 'fr') {
$mapado_id = $mapado_events['hydra:member'][$i]['#id'];
$mapado_date = \date('Y-m-d', strtotime($mapado_events['hydra:member'][$i]['nextDate']));
$result = $this->getContainer()
->get('doctrine')
->getRepository(MapadoIDs::class)
->findOneBy(['mapado_id' => $mapado_id]);
if ($result == null) {
echo 'event existe pas, ajout en bdd'.PHP_EOL;
$MapadoIDs = new MapadoIDs();
$MapadoIDs->setMapadoId($mapado_id);
$this->em->persist($MapadoIDs);
$mapado = json_decode($response, JSON_PRETTY_PRINT);
$event = new Event();
$event->setLongitude($mapado['hydra:member'][$i]['address']['longitude']);
$event->setLatitude($mapado['hydra:member'][$i]['address']['latitude']);
$event->setTitle($mapado['hydra:member'][$i]['title']);
$event->setDate($mapado_date);
$event->setFormattedAddress($mapado['hydra:member'][$i]['address']['formattedAddress']);
$event->setCity($mapado['hydra:member'][$i]['address']['city']);
$event->setLocale($mapado['hydra:member'][$i]['locale']);
$event->setActivityType($mapado['hydra:member'][$i]['activityType']);
$event->setDescription($mapado['hydra:member'][$i]['description']);
$this->em->persist($event);
}
}
}
}
$this->em->flush();
curl_close($curl);
if ($err) {
echo "cURL Error #: " . $err;
} else {
echo $response;
}
}
}
for better readability:
https://pastebin.com/CTu5gb8t
Expected result is a json output in my console.
Actual result is an error thrown preventing me from inserting results into my database.
Could you tell me if I'm missing something that could result in this error ?
It's a long and detailed post so that you can understand better my problem.
Well I solved my problem and it was not a date problem.
The problem was with the itemsPerPage query parameter requesting too much data and then throwing an error.
I set it up to 400 and everything is working as expected.

Facebook Error #100 when uploading Offline Conversions using Marketing API

I am using the the Facebook Marketing API to upload offline conversions.
The attached code was working until about 2 weeks ago and now reports the following error.
{"error":{"message":"(#100) The parameter data is required","type":"OAuthException","code":100,"fbtrace_id":"HkpzkWB1I5g"}}
I don't understand why it should simply stop working after working as expected for so long. I don't know how to fix it. Any ideas?
$data=array();
$data["match_keys"]["email"]=$emails;
$data["match_keys"]["phone"]=$mobiles;
$data["match_keys"]["fn"]=hash("sha256",$first_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ct"]=hash("sha256",$suburb);
$data["match_keys"]["zip"]=hash("sha256",$postcode);
$data["match_keys"]["country"]=hash("sha256","Australia");
$data["event_time"] = strtotime($order_date);
$data["event_name"] = "Purchase";
$data["currency"] = "AUD";
$data["value"] = $order_total;
$data['order_id']=$order_id;
$access_token = '<access_token_0>';
// PURCHASE DATA
$data_json = json_encode(array($data));
$fields = array();
$fields['access_token'] = $access_token;
$fields['upload_tag'] = uniqid() // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$ch = curl_init();
curl_setopt_array($ch, array(
// Replace with your offline_event_set_id
CURLOPT_URL => "https://graph.facebook.com/v2.12/1696501357346693/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data",
"Accept: application/json" ),
));
$result = curl_exec($ch);
echo "\nResult encode";
echo ($result);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Same thing just started happening here. Exact same problem. I had to play around for hours... But to get it working, I commented out
//"content-type: multipart/form-data",
and it started to work for me. Please let know if that also solves your problem.
It simply means that data is not sent as per documentation. I was facing this issue as in my case "contents" parameter was passing empty string, instead of documentation says that "contents" parameter should contain atleast 2 parameters, that is, quantity and id.
Go through documentation and you can compare your value format with documentation.
Here is link for documentation :- https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data#content-ids

Transmitting POST-event to Google Calendar using Perl and Net::OAuth2

I'm developing a webapp in Perl and try to create events in user's Google Calendar with OAuth2. Authentication and requesting calendar-data is working fine, I'm just totally stuck when it comes to sending a POST-request and attaching JSON- or hash-data to it. Are there methods coming with the module for this? The documentation does not point me anywhere here.
I guess LWP would provide ways, but this seems like a lot of overhead.
Here is how i accomplished getting calendar-events so far (as a simple console-app for now):
use Net::OAuth2::Profile::WebServer;
my $auth = Net::OAuth2::Profile::WebServer->new
( name => 'Google Calendar'
, client_id => $id
, client_secret => $secret
, site => 'https://accounts.google.com'
, scope => 'https://www.googleapis.com/auth/calendar'
, authorize_path => '/o/oauth2/auth'
, access_token_path => '/o/oauth2/token'
, redirect_uri => $redirect
);
print $auth->authorize_response->as_string;
my $code=<STDIN>;
my $access_token = $auth->get_access_token($code);
my $response = $access_token->get('https://www.googleapis.com/calendar/v3/calendars/2j6r4iegh2u8o2409jk8k2g838#group.calendar.google.com/events');
$response->is_success
or die "error: " . $response->status_line;
print $response->decoded_content;
Thanks a lot for your time!
Markus
I guess it's time to answer my own question.
To transmit JSON in a POST-request (creating a calendar-event) I ended up using LWP::UserAgent and HTTP::Request. For setting the content-type I first had to create an HTTP::Request-object and set header and data:
my $req = HTTP::Request->new( 'POST', 'https://www.googleapis.com/calendar/v3/calendars/<calendarID>/events' );
$req->header( 'Content-Type' => 'application/json' );
$req->content( "{ 'summary': 'EventName', 'start': { 'dateTime': '2015-02-11T20:48:00+01:00' }, 'end': { 'dateTime': '2015-02-11T22:30:00+01:00' } }" );
Then I created an LWP::UserAgent-object, appended the OAuth2-token to it and let it fire the request:
my $apiUA = LWP::UserAgent->new();
$apiUA->default_header(Authorization => 'Bearer ' . $access_token->access_token() );
my $apiResponse = $apiUA->request( $req );
It's that simple. Would've been a lot nicer to do this all-in-one with Net::OAuth2, though.

Getting token works, but making payment not

I'm making a class to make a payment with paypal.
Getting a token via the function getToken() works and it spits out a good response (according to the documentation).
However, when I'm using that token to build up a payment with the same sendAPICall() used for the token; it only returns a empty string (according to var_dump() ).
If I copy the exact curl command from the api-information and paste the beare-token; it works. So something is wrong with my API call....
Clearly I'm missing something. Could anyone point me to the error?
The function which gets the Bearer-token:
public function getToken(){
$headers = array(
"Accept-Language" => 'en_US',
"Accept" => "application/json"
);
$t = json_decode($this->sendAPICall('grant_type=client_credentials', '/oauth2/token', $headers, true));
if($t->error){
$this->error = $t->error_description;
$this->token = NULL;
return false;
}else{
$this->token = $t;
return true;
}
}
The function which should make the payment after checking there is a token available.
public function makePayment(){
$this->getToken();
if($this->error){
return false;
}else{
$d = '{"intent":"sale",
"redirect_urls":{
"return_url":"'.$this->config['returnURL'].'",
"cancel_url":"'.$this->config['cancelURL'].'"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"'.$this->amount.'",
"currency":"'.$this->config['currency'].'"
},
"description":"'.$this->description.'"
}
]
}';
$headers = array( "Authorization" => $this->token->token_type . ' ' . $this->token->access_token,
"Content-type" => "application/json"
);
return $this->sendAPICall(urlencode($d), '/payments/payment', $headers, false);
}
}
And off course the connection with the paypal API, where I'm using the $auth boolean to make the difference between sending the userpwd or using the token:
private function sendAPICall($data, $url, $headers, $auth=true){
$ch = curl_init();
$options = array( CURLOPT_URL => $this->config['endpoint'].$url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
);
if($auth){
$options[CURLOPT_USERPWD] = $this->config['client_id'].':'.$this->config['client_secret'];
};
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
return curl_exec($ch);
}
It does not look like this code snippet is passing HTTP headers correctly. CURLOPT_HTTPHEADER takes a unideimensional array with values of the form "headername: value". You need
$headers = array(
"Authorization: " . $this->token->token_type . ' ' . $this->token->access_token,
"Content-type: application/json"
);
Also consider
Checking for curl_errno($ch) / curl_error($ch) and the HTTP response code (curl_getinfo($ch, CURLINFO_HTTP_CODE)) to see if the call was successful.
Creating the request data as an associative array and using json_encode($data) when calling sendAPICall(). This is far easier than manipulating JSON strings manually.

SOAP Client Request --> Bad Request

I've been asked to look into syncing data using a SOAP service. I don't really know SOAP very well at all and I get a Bad Request Error.
The function I'm trying to call is a test echo function:
public string EchoAuthenticated(string text)
Each time I call it I get an error.
I have commented out the username / password setting as I don't know the username and password right now and my contact person is on leave :( Right now though I'd be perfectly happy just to get an authentication failed message rather than an error...
If anyone could point me in the right direction here please...
Thanks,
John
<?php
$apiUrl = 'https://exdev.api.propctrl.co.za/v3/Integration.svc?wsdl';
$options = array( 'trace' => 1, 'exceptions' => 1, 'soap_version' => SOAP_1_2);
try
{
$client = new SoapClient($apiUrl, $options);
//$data = array(
// 'Username' => "test",
// 'Password' => "test"
//);
//$header = new SoapHeader('https://exdev.api.propctrl.co.za/v3/', 'CredentialsHeader', $data, false);
//$client->__setSoapHeaders($header);
var_dump($client->__getFunctions());
print $client->EchoAuthenticated("Test String");
var_dump($client->__getLastRequest());
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
You might try something like:
...
$client = new SoapClient($apiUrl, $options);
var_dump($client->__getFunctions());
$auth = array("Username" => "John", "Password" => "secret",
"IsP24Credentials" => false);
$header = new SoapHeader("https://www.propctrl.com/", "CredentialsHeader",
$auth, FALSE);
$client->__setSoapHeaders($header);
print $client->EchoAuthenticated(array(
"text" => "My text to be echoed."
));
var_dump($client->__getLastRequest());
...
This should result in a request SOAP request like this:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="https://www.propctrl.com/v3" xmlns:ns2="https://www.propctrl.com/">
<env:Header>
<ns2:CredentialsHeader>
<ns2:IsP24Credentials>false</ns2:IsP24Credentials>
<ns2:Password>secret</ns2:Password>
<ns2:Username>John</ns2:Username>
</ns2:CredentialsHeader>
</env:Header>
<env:Body>
<ns1:EchoAuthenticated>
<ns1:text>My text to be echoed.</ns1:text>
</ns1:EchoAuthenticated>
</env:Body>
</env:Envelope>
As a side note, you might have a look at http://www.soapui.org/. This tool helps greatly with web service development.