Google Maps Geocoding API Stopped working (simple?) - google-maps-api-3

The code below has worked fine for quite some time but just stopped working. I did recently move to a new server but that wouldn't affect anything here, would it?? All I'm trying to get is lat/lng, but now it's returning nothing. Any help is appreciated!
$address = '127+East+Redlands+Blvd+92373';
$geocode = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address ='.$address.'&key=MY KEY WAS HERE');
$output = json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;

Turns out it was related to the server move after all. The new server had
[allow_url_fopen] disabled in php.ini. Enabled that and all is well again. :D

Related

Basic Example of Google Calendar API using Google API PHP Client

I have a property website where I have listed multiple properties. Each property has a Google Calendar and when the property is booked on that particular day, then a note is added on that day for that particular calendar.
I was doing all this manually, where I was updating the HTML of the website by showing the availability with a layout like this.
Now I am trying to make all this automated by using the Google Calendar API where I can display the booking of each property in a calendar like the example above.
I am trying to use the Google API PHP Client Library which is located at https://github.com/google/google-api-php-client
My biggest problem here is that I am unable to find any basic example of this also over the internet. Google pages are not showing the full examples.
For example, the guide page of Google shows just one example of "books", which I don't need at all.
I have searched all over the internet for some basic examples of the code but unable to find it at all. I search stackoverflow itself but all the codes that I have find are really confusing and all of them are different.
Moreover, most of them already "know" about it so there is no way to understand what is required.
If someone has a simple example where I can pull events of a day of a calendar, please post it here.
Also if you know of some other way to display the availability like the image above, would be great help !
Thanks.
What the heck, I'll repost an answer I gave from this question:
if($refresh_token_accessed_from_my_database) {
//If session contains no valid Access token, get a new one
if ($client->isAccessTokenExpired()) {
$client->refreshToken($refresh_token_accessed_from_my_database);
}
//We have access token now, launch the service
$this->service = new Google_Service_Calendar($client);
}
else {
//User has never been authorized, so let's ask for the ok
if (isset($_GET['code'])) {
//Creates refresh and access tokens
$credentials = $client->authenticate($_GET['code']);
//Store refresh token for further use
//I store mine in the DB, I've seen others store it in a file in a secure place on the server
$refresh_token = $credentials['refresh_token'];
//refresh_token->persist_somewhere()
//Store the access token in the session so we can get it after
//the callback redirect
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
if (!isset($_SESSION['access_token'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$this->service = new Google_Service_Calendar($client);
}
When I built my project I started from the tutorial Morfinismo post in the comments, but I had a couple of problems following that one. I've made comments to describe the general flow and some potential problem points, you may want to compare those notes with the other tutorial if you're not too clear about what is going on.

Payum - How to repeat Paypal payment when user close browser being on paypal side.

I have an ExpressCheckout up and running. Now I want to give the user the chance to make the payment at a later time. For example he closes the paypal process I keep data saved.
I guess this must be pretty straightforward but somehow it wont redirect me to paypal anymore. The only thing I did so far is to use the identifier to find an existing model instead of creating a new one. This part works so it'll find the specific record of the PaypalExpressPaymentDetails table. But as I said it wont redirect to paypal. Here is the code:
$paymentName = 'demo_paypal';
$storage = $this->get('payum')->getStorageForClass(
'Demo\UserBundle\Entity\PaypalExpressPaymentDetails',
$paymentName
);
/** #var $paymentDetails PaymentDetails */
$paymentDetails = $storage->createModel();
$paymentDetails->setPaymentrequestCurrencycode(0, $currency);
$paymentDetails->setPaymentrequestAmt(0, $amount);
$storage->updateModel($paymentDetails);
$captureToken = $this->getTokenFactory()->createCaptureToken(
$paymentName,
$paymentDetails,
'payments_transaction_success'
);
$paymentDetails->setReturnurl($captureToken->getTargetUrl());
$paymentDetails->setCancelurl($captureToken->getTargetUrl());
$paymentDetails->setInvnum($paymentDetails->getId());
$storage->updateModel($paymentDetails);
Executed Controller:
...
$identificator = new Identificator($entity->getId(), 'Demo\UserBundle\Entity\PaypalExpressPaymentDetails');
$captureToken = $this->payLateByPaypal($entity->getAmount(), "USD", $entity->getId(), $identificator);
return $this->redirect($captureToken->getTargetUrl());
Any ideas?
I've reproduce it in the sandbox. Unfortunately it is a known issue. If the user logged in and access the page second time the payment considered as canceled. That's done this way to avoid endless redirection between your site and paypal one. I dont see an easy way to solve it.
UPDATE
In version 1.0 the cancel issue is handled correctly.

Flex not wanting to use https as specified

I have a small little swf that I'm trying to get to work while the webpage is using https/ssl. I'm passing into the swf the fact that the page is using https and have conditional logic as such:
if ( secure ) {
pollChannel = new AMFChannel('my-secure-polling-amf','https://' + globalDomain + '/flex2gateway/cfamfpollingsecure');
}
else {
pollChannel = new AMFChannel('cf-polling-amf','http://' + globalDomain + '/flex2gateway/cfamfpolling');
}
When the page is http it uses the correct endpoint no problem. When secure == true for whatever reason the browser is reporting its using http://somedomain.local/flex2gateway/cfamfpollingsecure, not https.
Anybody have a clue why??? I don't understand why it would adjust itself like that.
Any help is much appreciated!
Lucky for you I had the exact same mystery issue last week and the fix is extremely simple (once you know where to look, that is; I've been digging through the source code for a while to figure it out):
you just have to use SecureAMFChannel instead of the regular AMFChannel

"An active access token must be used" (Dec 2012) && The proper way to set up Facebooks PHP-SDK for Ajax calls to get the user-id

This is giving me quite some headache. I have an page-tab-application, where DB-interaction uses the facebook-user-id to assign and save data and also to check user permissions. Until a weak ago everything was working fine, but now with the upcoming december-changes this setup doesnt work anymore:
config.php:
$facebook = new Facebook( array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
index.php:
includes config.php and gets the signed request (not important for the question
javascript.js:
calls the read-user-status.php and handles the data
read-user-status.php:
gives json-response, includes config.php and calls the $facebook -> getUser()-function to get the uid
Even when called from the index.php directly after page-load, I sometimes get the uid and sometimes I don't. Strangly enough I usually have to wait a little until I reload the page and then it works again. But this isn't always the case. This all is just very strange to me.
EDIT: Should have mentioned that this call:
$uid = $facebook -> getUser();
if ($uid) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$uid = FALSE;
echo "EXCEPTION $e";
}
}
gives out "EXCEPTION An active access token must be used to query information about the current user".
I know there quite a lot of similar questions out there, but none of the answers were helpful to my particular (and probably to the new breaking changes relied) problem.
EDIT2: I now suppose that it is a sdk-bug (https://developers.facebook.com/bugs/238039849657148 , thanks to CBroe). Any recommendations for a work-around are of course very welcome.
EDIT 3, TEMPORARY SOLUTION
Everytime you make an ajax request, you post the token you get from the FB.getLoginStatus or FB.login and read it out in the php file and set it via $facebook -> setAccessToken. Not suitable in all circumstances (you definately need to use post), is slower and brings some security issues, but still works.
Sounds like you are affected by the bug I reported beginning of November, https://developers.facebook.com/bugs/238039849657148
They’ve confirmed it and say they’re working on a fix – but since the change is only a few days away now, they should hurry up a little …
I got this working by doing the following...
if(!$user){
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email',
'redirect_uri' => $app_url
));
header('Location: ' . $loginUrl);
}
I also added my app to be integrated with:
Website with Facebook login
App on Facebook
Page Tab
try by adding access token to request.
$accessToken = $facebook->getAccessToken();
$user_profile = $facebook->api('/me?access_token=' . $accessToken);
I found a work-around for this, until it is fixed (which it seems like, wont be in time until the changes take place).
Everytime you make an ajax request, you post the token you get from the FB.getLoginStatus or FB.login and read it out in the php file and set it via $facebook -> setAccessToken. Not suitable in all circumstances (you definately need to use post), is slower and brings some security issues, but still works.
if it you are lucky and your version of php sdk still registers session variables than right after _graph method declaration:
//find this method below
protected function _graph ($path, $method = 'GET', $params = array ())
{
//paste right after _graph method declaration code below:
if (isset($_SESSION["fb_".$this->getAppId()."_access_token"]))
{
$this->setAccessToken($_SESSION["fb_".$this->getAppId()."_access_token"]);
}
//till here
//and you are good to go
//remember: your version of sdk must be registering access token variable in session
//right after ajax call
//i used git to get version before last commit of sdk published on github

How to make wp_insert_post_data and sessions work together properly?

I'm trying to process the post content before saving it to database and inform user if there was any error. I'm using wp_insert_post_data filter, sessions and admin_notices, since it seems to be the only simple solution to throw the error message to edit screen in admin panel after publishing. However, I ran into strange problem - the code seems to run twice, so when I have:
function notices(){
if(!empty($_SESSION['notices'])) print $_SESSION['notices'];
unset ($_SESSION['notices']);}
add_action( 'admin_notices', 'notices' );
add_filter('wp_insert_post_data', 'processdata', '99', 2);
function processdata($data) {
$processed_content = filterthis($data['post_content']);
if($processed_content!='error') {
$data['post_content'] = $processed_content;
$_SESSION['notices'] .= '<div class="updated"><p>Everything is ok</p></div>';
return $data;
} else {
$_SESSION['notices'] .= '<div class="error"><p>Something went wrong</p></div>';
return $data;}
I receive two messages. I've made some tests and it seems that first is for content that is to be saved in database and second for the "old" content (already saved). For example: if previous content was "wrong" and the one to be saved is "ok", the first message is "ok" and second "error" and so on. However, all messages are generated on the same time (so this is not some kind of caching problem, I suppose).
What is even more strange for me, is that if I use this simple code:
add_filter ('wp_insert_post_data', 'filterthis', '99', 2);
function filterthis($data){
$date = date('H:i:s');
$_SESSION['my_admin_notices'] .= '<div class="updated"><p>This is a message from '.$date.'</p></div>';
$data['post_content'] .= $date;
return $data;
}
I get also two messages, but only one piece of timing data appended to post content - identical to the one delivered by the first message. So it seems like the code runs twice, but only for the first time it saves the content to database... I'm totally confused after seven hours of googling and reading Codex. Maybe the solution is trivial, but I'm not really a PHP programmer, just learning it for a while, so I would be very glad if someone here could help me.
I have also face the same problem when I made custom field validation before publish the post. Also when update the published post this filter gives strange behavior. so I have decide to go for client side validation.
Which is very simple DOM operation.
Please refer following link if you want to use client side validation.
http://greatindiaclub.oliwy.net/?p=1101

Resources