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

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.

Related

xmlrpc getting an error xmpp user register

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.

What is this? (Facebook Offline Conversions API) Error #21009 - The data set upload is temporarily not ready

We have been uploading to Facebook's Offline Conversion API for the past 3 weeks with no issues. Suddenly, Facebook is returning this error:
(#21009) The data set upload is temporarily not ready.
See below code for full JSON payload.
Our Auth Token is still valid. (e.g. Not expired, still valid)
According to this tool: https://developers.facebook.com/tools/debug/accesstoken/
# I had to remove these fields for privacy reasons
define('FACEBOOK_APP_ACCESS_TOKEN', 'YOUR TOKEN HERE');
define('FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID', 'YOUR PIXEL ID HERE');
# Be sure to change the email/name fields accordingly
$event_name='test-upload';
$data = array();
$data["match_keys"] = array();
$data["match_keys"]['email'] = hash('sha256', 'bob.ross#example.com');
$data["match_keys"]['fn'] = hash('sha256', 'bob');
$data["match_keys"]['ln'] = hash('sha256', 'ross');
$data["match_keys"]['gen'] = hash('sha256', 'm');
$data["event_time"] = time();
$data["event_name"] = $event_name;
$data["currency"] = "USD";
$data["value"] = '0.00';
// Turn Data to JSON
$data_json = json_encode(array($data));
// Fill available fields
$fields = array();
$fields['access_token'] = FACEBOOK_APP_ACCESS_TOKEN;
$fields['upload_tag'] = $event_name . '-' . time(); // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$url = 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/events';
$curl = curl_init($url);
curl_setopt_array($curl, array(
// Replace with your offline_event_set_id
CURLOPT_URL => 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/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" ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Expected result from Facebook:
{"id":"36485444079550","num_processed_entries":1}
Actual result from Facebook
{
"error": {
"message": "(#21009) The data set upload is temporarily not ready.",
"type": "OAuthException",
"code": 21009,
"fbtrace_id": "GeofD5QsXdI"
}
}
I would add a comment instead of an "answer" but I don't quite have the points yet. The commenters on the Facebook thread (https://developers.facebook.com/support/bugs/1052442614962359/) have had this magically resolve overnight, and I experienced the same (problem happening and no explanation, then magical resolution and no explanation). It seems like Facebook may have fixed whatever was causing the issue.

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

IPP CustomerAgg 401 on getAccountTransactions

The user flow I'm building for my application is that users can click on myAccounts and I'll display the getCustomerAccounts Results. That works perfectly. Then for each account I have a hyperlink called get transactions. That takes the user to a new page that should list out the transactions for that account. For some reason I'm always getting a 401 Code:ApplicationAuthenticationFailed when I call getAccountTransactions even though the previous call of getCustomerAccounts worked fine.
I'm confused as I imagine the authentication that is failing for the 401 is the exact same that works for the earlier call. Here is my code:
function get_transactions($accountID)
{
IntuitAggCatHelpers::GetOAuthTokens( $oauth_token, $oauth_token_secret);
$signatures = array( 'consumer_key' => OAUTH_CONSUMER_KEY,
'shared_secret' => OAUTH_SHARED_SECRET,
'oauth_token' => $oauth_token,
'oauth_secret' => $oauth_token_secret);
$txnStartDate = '2014-06-01'; // YYYY-MM-DD
$url = FINANCIAL_FEED_URL ."v1/accounts/$accountID/transactions?txnStartDate=$txnStartDate";
$action = 'GET';
$oauthObject = new OAuthSimple();
$oauthObject->setAction( $action );
$oauthObject->reset();
$result = $oauthObject->sign(
array
(
'path' => $url,
'parameters'=>
array
(
'oauth_signature_method' => 'HMAC-SHA1',
'Host' => FINANCIAL_FEED_HOST
),
'signatures'=> $signatures
)
);
$options = array();
$curlError = fopen('php://temp', 'rw+');
$options[CURLOPT_STDERR] = $curlError;
$options[CURLOPT_CUSTOMREQUEST] = $action;
$options[CURLOPT_URL] = $result['signed_url'];
$options[CURLOPT_HEADER] = 1;
$options[CURLOPT_VERBOSE] = 1;
$options[CURLOPT_RETURNTRANSFER] = 1;
$options[CURLOPT_SSL_VERIFYPEER] = true;
$options[CURLOPT_HTTPHEADER] = array
(
'Accept:application/json',
'Content-Type:application/json',
//'Content-Length:' . strlen( $postData ),
'Host:'. FINANCIAL_FEED_HOST,
//'Authorization:' . $result['header']
);
$curlError = fopen('php://temp', 'rw+');
$options[CURLOPT_STDERR] = $curlError;
$ch = curl_init();
curl_setopt_array( $ch, $options );
$responseText = urldecode( curl_exec( $ch ) );
echo $responseText;
//display curl http conversation
rewind( $curlError );
stream_get_contents( $curlError );
fclose( $curlError );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
return $responseText;
}
Using same certificate(.p12) please try the above getAccountTransaction call from APIExplorer tool.
https://developer.intuit.com/apiexplorer?apiname=CustomerAccountData
Usage Ref - https://developer.intuit.com/docs/0020_customeraccountdata/007_firstrequest
If that works well, then compare the request header and URL with the same from your above code. 401 suggests authentication error which comes when your OAuth header is not properly formed/incorrect. Above comparison should sort this out.
PN - While uploading .p12 file(SAML) in ApiExplorer, sometiems, I get the following error msg.
"Your certificate is invalid. Please use base64 encoded CER format and make sure that the file is not empty". If you get the same then this can't be tested in ApiExplorer.
Thanks
This worked for me:
$result = $oauthObject->sign(array(
'path' => FINANCIAL_FEED_URL . 'v1/accounts/400037865348',
'parameters'=> array('oauth_signature_method' => 'HMAC-SHA1',
'Host'=> FINANCIAL_FEED_HOST,
'txnStartDate' => '2014-01-01',
'txnEndDate' => '2014-08-29'),
'signatures'=> $signatures));
Found at https://intuitpartnerplatform.lc.intuit.com/questions/797819-how-to-get-txnstartdate-into-my-url-without-breaking-oauth-authentication.

Phalcon Paginator error: Syntax error, unexpected EOF

my problem is, every time I click in the paginator link in the view, the controller returns me this error:
Syntax error, unexpected EOF
What is this? EOF?
My controller:
$domicilios = Domicilios::find();
$paginator = new \Phalcon\Paginator\Adapter\Model(
array(
"data" => $domicilios,
"limit"=> 5,
"page" => $currentPage
)
);
$pagina = $paginator->getPaginate();
$this->view->setVar("estado", $estado);
$this->view->setVar("pagina", $pagina);
The content in the model Domicilios is returning right, but why the paginator keeps returning this error?
Thanks in advance!
EOF is end of file. there might be several issues. 1stly if you upload this file to server, there might be problems with upload process and file is not fully uploaded and you have broken end of file (EOF).
try converting your php file to utf8. you can do it with notepad++ and many other programs.
here are my working pagination:
$page = $this->request->get('page', 'int', 1);
$this->view->page = $page;
if ($page < 1) {
$page = 1;
}
$user = $this->session->get('auth');
$questions = Model_UserQuestion::find(array(
'user_id=:user_id:',
'bind' => array('user_id' => $user['id']),
"order" => "id DESC",
));
// Create a Model paginator, show 10 rows by page starting from $currentPage
$paginator = new \Phalcon\Paginator\Adapter\Model(
array(
"data" => $questions,
"limit" => $this->config->application->itemsPerPage,
"page" => $page
)
);
$page = $paginator->getPaginate();
$this->view->questions = $page->items;
notice that to get items you have to use this:
$page->items