p3k / mf2-instagram-shim
Description
This package is not auto-updated.
Last update: 2020-01-20 03:56:27 UTC
README
This module takes an Instagram URL and returns a data structure as if the URL had been marked up with a proper h-entry.
Usage
Bring in this library using composer, or just by including the src\p3k\instagram-shim.php
file.
{ "p3k/mf2-instagram-shim": "0.1.*", }
First, initialize the Instagram client with your credentials.
p3k\instagram\setup($instagramAccessToken);
Then you can call parseURL
with a URL to a photo and get back a nicely formatted h-entry
.
$data = p3k\instagram\parseURL('http://instagram.com/p/rhlnwxjcu9/');
Timezone
Instagram returns unix timestamps and does not include timezone information anywhere. However, photos that are taken at a location can be assumed to be in that timezone. To augment the parsed result so that the returned dates include timezone, you can provide a function that will be used to look up the timezone of photos if location data is available.
The function should take two arguments, latitude and longitude, and return a string of the timezone name such as "America/Los_Angeles".
The code below will return the same timezone for all locations in the case that you want all your photos to be set to the same timezone.
p3k\instagram\timezoneLookup(function($lat,$lng){ return 'America/Los_Angeles'; });
The code below will use a remote web API to find the timezone given a location.
p3k\instagram\timezoneLookup(function($lat,$lng){ $ch = curl_init('http://timezone-api.geoloqi.com/timezone/' . $lat . '/' . $lng); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); if($response) { $timezone = json_decode($response); if($timezone) { return $timezone->timezone; } } return null; });
License
Copyright 2014 by Aaron Parecki
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.