onlinecode

PHP Create Instagram location Image Fetcher

PHP Create Instagram location Image Fetcher

In this post PHP create Instagram location Image Fetcher, i will be able to show you the way to create a simple Instagram location image fetcher in PHP by exploitation google map REST API and Instagram REST API. This application can use google map API to urge latitude and great circle|great circle} of a selected location then provide that latitude and longitude to Instagram API to fetch recent twenty public photos labeled thereupon location.

If you’re not accustomed to REST then REST stands for realistic State Transfer that could be a approach of accessing net services. quite seventy fifth of net services use REST. you’ll be able to access a REST service by employing a straightforward HTTP GET or POST requests. The API provide output most likely in JSON format and you’ll be able to rewrite it in PHP and use it in your application.

Now lets starts for PHP Create Instagram location Image Fetcher

There are two components during this application.

1) Fetch Latitude and line of longitude of a selected location exploitation google map API

you’ll be able to get each latitude and line of longitude of a location by a straightforward GET request within the following uniform resource locator. you’ll get JSON output.

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

Now lets checks its PHP codes for PHP Create Instagram location Image Fetcher

<?php
$get_location = $_POST['location'];
$map_url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($get_location);
	
// get map json
$map_json = file_get_contents($map_url);
// get map array
$get_map_array = json_decode($map_json,true);

// set latitude
$get_lat = $get_map_array['results'][0]['geometry']['location']['lat'];
// set longitude	
$get_lng = $get_map_array['results'][0]['geometry']['location']['lng'];

2) Get Latest pictures by exploitation Instagram API

The Instagram location API needed latitude and line of longitude and a ACCESS TOKEN . Here is that the REST API uniform resource locator. The output is additionally in JSON Format.

currently so as to get access token there square measure once more 2 ways

First technique for PHP Create Instagram location Image Fetcher

Register your app in Instagram developer console https://www.instagram.com/developer/ and obtain access token by exploitation once more exploitation GET Request like below

https://instagram.com/oauth/authorize/?client_id=56df9______b9cad&redirect_uri=http://localhost/test/instagram/&response_type=token&scope=basic+public_content+follower_list+comments+relationships+likes

however this access token may be wont to fetch your own data solely not the other users. Inorder to fetch public users data you would like to submit your app in instagram that could be a terribly complicated method therefore second technique

Second technique (Recommended and vary Easy) for PHP Create Instagram location Image Fetcher

simply visit following link to urge the Access Token. :: http://services.chrisriversdesign.com/instagram-token/

Once you get the access token then the PHP code for attractive pictures of that location is given below.

<?php

$instagram_url = "https://api.instagram.com/v1/media/search?lat=".$get_lat."&lng=".$get_lng."&access_token=".$add_access_token;

$instagram_json = file_get_contents($instagram_url);

$instagram_array = json_decode($instagram_json,true);

The Complete Code is given below for PHP Create Instagram location Image Fetcher

this is The Complete Code is given below for PHP Create Instagram location Image Fetcher, hear you have to pass latitude and longitude and you will get image of that location.

<?php
if(!empty($_POST['location']))
{
	// add MY-ACCESS-TOKEN
	$add_access_token = "51-MY-ACCESS-TOKEN-3e";
	$get_location = $_POST['location'];
	$get_map_url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($_POST['location']);
	
	$json_map = file_get_contents($get_map_url);
	$get_map_array = json_decode($json_map,true);
	
	$get_lat = $get_map_array['results'][0]['geometry']['location']['lat'];
	$get_lng = $get_map_array['results'][0]['geometry']['location']['lng'];
	
	$instagram_url = "https://api.instagram.com/v1/media/search?lat=".$get_lat."&lng=".$get_lng."&access_token=".$add_access_token;

    $get_instagram_json = file_get_contents($instagram_url);

    $instagram_array = json_decode($get_instagram_json,true);
	
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>PHP Create Instagram location Image Fetcher - onlinecode</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="jumbotron text-center">
  <h1>PHP Create Instagram location Image Fetcher - onlinecode</h1>
</div>
  
<div class="container">
	<div class="row subdiv">
		<div class="subdiv col-md-8 col-md-offset-2">
			<form action="#" method="POST">
			  <div class="form-group subdiv">
				<label for="location">Location Name</label>
				<input type="test" class="form-control" name="location" value="<?php if(!empty($_POST['location']))echo $_POST['location'];?>">
			  </div>
			  <button type="submit" class="btn btn-primary btn-block">SEARCH</button>
			</form>
        </div>
    </div>
	<p>&nbsp;</p>
	<div class="row subdiv">	    
	<?php
	// check instagram_array is emplty 
	if(!empty($instagram_array))
	{   ?>	
		<div class="col-md-8 col-md-offset-2 subdiv">
			<h2 style="text-align:center;">Location : <?php echo $_POST['location']; ?> - onlinecode</h2>
			<p>&nbsp;</p>
			<?php 
				// get data from instagram_array
				foreach($instagram_array['data'] as $images)
				{
			?>
					<div class="well subdiv">
						<!-- get images form instagram array -->
						<img class="img-responsive subdiv" style="padding-left:41px;" src="<?php echo $images['images']['standard_resolution']['url'] ?>" alt="search Instagram Photos">
						<p>&nbsp;</p>
					</div>
			<?php
				} // end foreach
			?>	
		</div>
	<?php   
	} // end if
	?>
    </div>
</div>
</body>
</html>

You also like google recaptcha using javascript and google recaptcha using php and PDO using Prepared Statements a Complete Reference

Exit mobile version