Google maps - Facebook Places fake location using JSON - php

I am doing some research regarding location based social networking and I am trying to see whether I can fake a location by modifying the JSON that google returns to the Firefox browser.
Firstly, I have typed about:config in the firefox browser and got all the config settings up and changed the param of geo.wifi.uri to a page that returns JSON location below.
<?php
header('Content-type: application/json');
$longitude = "-73.98626";
$latitude = "40.75659";
$accuracy = "10";
$geoArray = array( 'location'=>array(
'latitude'=>$latitude,
'longitude'=>$longitude,
'accuracy'=>$accuracy ) ) ;
$geoJson = json_encode( $geoArray ) ;
echo $geoJson ;
?>
It has got to a stage where I can select a place and the check in button appears but when i press it, it just says loading..
I am using a firefox user agent iphone 3.0 setting to get the check-in option

Does your faked location work in something like this: http://html5demos.com/geo ? There is an access_token field in the expected response that your JSON is missing: try adding that. And you may want to add an address field as well. This is the structure you need:
{"location":
{"latitude": 40.75659,
"longitude": -73.98626,
"address":{"country":"United States","country_code":"US","region":"<statename>",
"city":"<city name>","street":"<street name>","street_number":"<number>","postal_code":"<zip>"},"accuracy":10.0},
"access_token":"<honestly not sure what this is or how it is interpreted>"}

Related

Read data from object json with php

I am building my log system, for my software in php.
Data collection via: https://ipinfo.io/
As shown in the screenshot, just make a json_decode to read them.
Only problem for the privacy object that I can't show:
example working with for example the city parameter:
//Gets the IP Address from the visitor
$PublicIP = $_SERVER['REMOTE_ADDR'];
//Uses ipinfo.io to get the location of the IP Address, you can use another site but it will probably have a different implementation
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
//Breaks down the JSON object into an array
$json = json_decode($json, true);
$city = $json['city'];
echo $city;
instead when I have to go into privacy, it doesn't give me anything back, what am I doing wrong?
$PublicIP = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
$json = json_decode($json, true);
$vpn = $json["privacy"]["vpn"];
echo $vpn
If vpn is false, then you won't see anything because false shows up as blank when echoed.
Try something like echo ($vpn == true ? "Yes" : "No"); instead. Or use var_dump($vpn);
See also PHP - Get bool to echo false when false.
There are two issues at least:
Privacy data is only available if you have a token (i.e. you signed up), and that too only if you purchased the privacy data - see their pricing page and the addons page. Then you'll have to include the token in your request.
You are requesting for /geo, which will only give back geographical data. Don't put that suffix in the request URL.
I suggest you carefully read https://ipinfo.io/developers and https://ipinfo.io/developers/data-types#privacy-data in particular for your use case.

Google Sheets API with php - Find a cell value

I am using the Google Sheets API with PHP and reading a sheet, I need to find a row and update its content.
I am currently iterating over the rows, looking for the value, but as the sheet grows, this seems rather inefficient. Is there a way to search for a cell, to retrieve the row, so I can then update?
My code to iterate is as follows.
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getById("xxx sheet id xxx");
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
$CellFeed = $worksheet->getCellFeed();
foreach ($CellFeed->getEntries() as $E)
{
$r = $E->getRow();
/* ...... */
}
I believe your goal as follows.
You want to search a value from the specific column in the Spreadsheet and want to retrieve the row numbers of searched rows.
You want to achieve this using PHP.
Issue and workaround:
In that case, unfortunately, when Sheets API is used, in the current stage, it is required to do the following flow.
Retrieve all values from the sheet you want to search.
Retrieve the row and column numbers from the retrieved values.
This might be the same with your current script. Because in the current stage, there are no methods for directly searching the values in Sheets API. So in this answer, as a workaround, I would like to propose to use Web Apps created by Google Apps Script. When Google Apps Script is used, the searched row numbers can be retrieved by the TextFinder which is the built-in method. And the process cost of TextFinder is low. So I proposed it.
Usage:
Please do the following flow.
1. Create new project of Google Apps Script.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
It is required to put this Google Apps Script project to the same Google Drive of the Spreadsheet you want to use.
2. Prepare script.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const sheet = SpreadsheetApp.openById(e.parameter.spreadsheetId).getSheetByName(e.parameter.sheetName);
const res = sheet.getRange(1, 2, sheet.getLastRow()).createTextFinder(e.parameter.searchValue).findAll().map(r => r.getRow());
return ContentService.createTextOutput(JSON.stringify({rowNumbers: res})).setMimeType(ContentService.MimeType.JSON);
}
3. Deploy Web Apps.
On the script editor, Open a dialog box by "Publish" -> "Deploy as web app".
Select "Me" for "Execute the app as:".
By this, the script is run as the owner.
Select "Anyone, even anonymous" for "Who has access to the app:".
In this case, no access token is required to be request. I think that I recommend this setting for testing this workaround.
Of course, you can also use the access token. When you use the access token, please include one of scopes for Drive API like https://www.googleapis.com/auth/drive.readonly.
And also, I think that a key value can be used as the query parameter instead of the access token.
Click "Deploy" button as new "Project version".
Automatically open a dialog box of "Authorization required".
Click "Review Permissions".
Select own account.
Click "Advanced" at "This app isn't verified".
Click "Go to ### project name ###(unsafe)"
Click "Allow" button.
Click "OK".
Copy the URL of Web Apps. It's like https://script.google.com/macros/s/###/exec.
When you modified the Google Apps Script, please redeploy as new version. By this, the modified script is reflected to Web Apps. Please be careful this.
4. Testing Web Apps using PHP script.
Please set the URL of your Web Apps to the following script. And, please set the spreadsheet ID, sheet name. From your replying, in this sample, the search value and column number are Pj/5678 and 2, respectively. 2 of searchColumn means the column "B".
<?php
$url = 'https://script.google.com/macros/s/###/exec'; // Please set the URL of Web Apps.
$q = array(
'spreadsheetId' => '###', // Please set the Spreadsheet ID.
'sheetName' => 'Sheet1',
'searchValue' => 'Pj/5678',
'searchColumn' => 2
);
$curl = curl_init();
$option = [
CURLOPT_URL => $url . '?' . http_build_query($q),
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true
];
curl_setopt_array($curl, $option);
$res = curl_exec($curl);
$obj = json_decode($res);
print_r($obj);
curl_close($curl);
?>
Result:
When above script is run, the following value is returned. The row numbers of searched rows are returned.
{"rowNumbers":[###, ###,,,]}
Note:
When you modified the script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to Web Apps. Please be careful this.
References:
Web Apps
Taking advantage of Web Apps with Google Apps Script
Class TextFinder

Centre Google Map marker on embeded map

Cannot get this to work for the life of me, and I can't figure out why.
Ok...
On a wordpress post i have a custom field 'Post Code'. The script I have picks up the value of this field, runs it past google to get Lat and Long values and embeds the map. This is what I have:
$postcode = urlencode( get_field("tutor_post_code")); // post code to look up in this case status however can easily be retrieved from a database or a form post
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=true"; // the request URL you'll send to google to get back your XML feed
$xml = simplexml_load_file($request_url) or die("url not loading");// XML request
$status = $xml->status;// GET the request status as google's api can return several responses
if ($status=="OK") {
//request returned completed time to get lat / lang for storage
$lat = $xml->result->geometry->location->lat;
$long = $xml->result->geometry->location->lng;
echo "$lat,$long"; //spit out results or you can store them in a DB if you wish
}
if ($status=="ZERO_RESULTS") {
//indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
}
if ($status=="OVER_QUERY_LIMIT") {
//indicates that you are over your quota of geocode requests against the google api
}
if ($status=="REQUEST_DENIED") {
//indicates that your request was denied, generally because of lack of a sensor parameter.
}
if ($status=="INVALID_REQUEST") {
//generally indicates that the query (address or latlng) is missing.
}
echo '<iframe width="100%" height="400" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=';
echo get_field("tutor_post_code");
echo '&zoom=13&center=';
echo "$lat,$long";
echo '&key=AIzaSyB8LLFEJV_Or1sj_u1PGKw12n6leDKND3o"></iframe>';
Any ideas why it's not centering the marker on the map?
Miro
I tried your code and it seems to be working fine.
One possibility is http://maps.googleapis.com/maps/api/geocode/xml?address=is returning a different result than your iframe Google Maps. (This does happen sometime.)
Like #Dr.Molle said, you don't really need to do center as it is default to center to the q point, unless you wants a different center.

Can't get Yelp API v2 (PHP) to work

I've been all over the web and its pretty unclear to me how to get the yelp api to work using the php code sample provided.
So far I have
Grabbed the sample php file from here https://raw.githubusercontent.com/Yelp/yelp-api/master/v2/php/sample.php
I have not modified this file at all except to add my authentication.
Gotten all of my tokens,keys and secrets
$CONSUMER_KEY = "GOT IT!";
$CONSUMER_SECRET = "GOT IT!";
$TOKEN = "GOT IT!";
$TOKEN_SECRET = "GOT IT!";
I am including the OAuth, which I got from here http://oauth.googlecode.com/svn/code/php/
require_once('OAuth.php');
In the read me document it states to simply go to the php file and check out the results
When I visit the page on my site, I get this error message(I removed my actual consumer key)
0 businesses found, querying business info for the top result ""
Result for business ""
found: {"error": {"text": "Signature was invalid", "id": "INVALID_SIGNATURE", "description": "Invalid signature. Expected signature base string: GET\u0026http%3A%2F%2Fapi.yelp.com%2Fv2%2Fbusiness%2F\u0026oauth_consumer_key%KEY%26oauth_nonce%3Db7869743b1599850a2db6e92fc2a6239%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1414090806%26oauth_token%3DyJMyLRsFiAIuKSuclV1d6pb0pwjwiEat%26oauth_version%3D1.0"}}
I just signed up for the api keys today and have checked and double checked and they are correct in the php file.
I've also attempted to add parameters to the url to see if I can get any results and its always the same error.
My end goal is to pull in all reviews for a business by using its phone number as a search parameter. If anyone can provide an example of how I would pass the parameter that would be so helpful too.
After getting and placing the token and secret from the app you created on Yelp. You have to edit one more thing in Sample.php on 13th last line (or line:138) you will see the following:
`$longopts = array(
"term:: /* Place Term here e.g. 'Bars' */ ",
"location:: /* Place Location here e.g. 'San Francisco, CA' */ ",
);`
Or the location can be change from your Yelp Developer ID by editing the location.
Hope you got the answer.
To get yelp business details using phone number:
You can try a http or curl request to
http://api.yelp.com/phone_search?phone=8009773609&ywsid=sQ3g4WLACeGWOFXXXXXXXX
ywsid = Yelp CONSUMER_KEY

How to get the IP address of the user and return the data in JSON

I am not a php expert. I develop android apps. In my app i am getting the user's ip address from this url http://ip2country.sourceforge.net/ip2c.php?format=JSON. As you can see when some open this url it returns some info including the IP address. I only want to get the IP and (if possible) country. Most of the time this url is busy and doesn't returns ip and gives max active user connections error. Can you please give me any php file which i can put in my own webhost and call the url to get ip. The data returned should be in json so i can parse it easily.
Thanks
<?php
$json = file_get_contents("http://ip2country.sourceforge.net/ip2c.php?format=JSON");
//this $json will have the response that the website sends.
echo json_encode($json);
?>
You can have this object wherever you call this php file and do the needful
Run this php file to check the output
Another way: EDIT
<?php
$visitor_ip = $_SERVER['REMOTE_ADDR'];
echo $visitor_ip;
$data1 = file_get_contents("http://api.hostip.info/?ip=$visitor_ip");
echo "<br> $data1";
?>
You can use PHP to get the users IP address via $_SERVER['REMOTE_ADDR']. You can then use an IP to Location lookup website to translate that into a country and merge the results:
$ip = $_SERVER['REMOTE_ADDR'];
$loc = json_decode(file_get_contents('http://ipinfo.io/'.$ip.'/json'), true);
$country = isset($loc['country']) ? $loc['country'] : 'Unknown';
$result = array('ip'=>$ip, 'country'=>$country);
header('Content-Type: application/json');
echo json_encode($result);
You get the IP address in PHP you have to use $_SERVER['REMOTE_ADDR'] then use http://ipinfo.io to pass that IP to this website. You can get the Location through JSON data, just follow the first answer on this question Getting the location from an IP address.
I have successfully implemented it by following the answer.

Categories