#!/usr/bin/php <?php $time_start = microtime(true); require_once __DIR__ . '/tests_common.php'; _wl('test "' . basename(__FILE__) . ''); require_once __DIR__ . '/../lib/OSM/Api.php'; $osmApi = new OSM_Api(); $xmlQuery = ' <osm-script> <union> <query type="relation" into="qr"> <has-kv k="boundary" v="administrative"/> <has-kv k="admin_level" v="8"/> <has-kv k="ref:INSEE" v="37001"/> </query> <recurse type="relation-node" from="qr"/> <recurse type="relation-way" from="qr"/> <recurse type="way-node"/> </union> <print /> </osm-script> '; $osmApi->queryOApi($xmlQuery); // getRelations, getWays, getNodes $relations = $osmApi->getRelations(); _assert(count($relations) == 1); $ways = $osmApi->getWays(); _assert(count($ways) == 8); $nodes = $osmApi->getNodes(); _assert(count($nodes) == 680); $objects = $osmApi->getObjects();
$auth_method = 'Basic'; $auth_basic_user = ''; $auth_basic_password = ''; // $auth_method = 'OAuth'; $auth_oauth_consumer_key = ''; $auth_oauth_consumer_secret = ''; $auth_oauth_token = ''; $auth_oauth_secret = ''; // $auth_method = ''; // Override above parameters into you own file: include __DIR__ . '/../../secrets.php'; // // =================================================== $osmApi = new OSM_Api(array('url' => OSM_Api::URL_DEV_UK, 'url4Write' => OSM_Api::URL_DEV_UK)); if ($auth_method == 'Basic') { _wl(' using Basic auth with user="******"'); $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password)); } else { if ($auth_method == 'OAuth') { _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"'); $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret); $oauth->setToken($auth_oauth_token, $auth_oauth_secret); $osmApi->setCredentials($oauth); } } // http://api06.dev.openstreetmap.org/api/0.6/relation/500 // http://api06.dev.openstreetmap.org/api/0.6/way/8184 // http://api06.dev.openstreetmap.org/api/0.6/node/611571 // get a node
#!/usr/bin/php <?php /** * To change this template, choose Tools | Templates * and open the template in the editor. */ $time_start = microtime(true); require_once __DIR__ . '/tests_common.php'; _wl('test "' . basename(__FILE__) . ''); require_once __DIR__ . '/../lib/OSM/Api.php'; $osmApi = new OSM_Api(); $node = $osmApi->getNode('611571'); $serialData = serialize($osmApi); $osmApi = unserialize($serialData); $node = $osmApi->getNode('611571'); $time_end = microtime(true); _wl('Test well done in ' . number_format($time_end - $time_start, 3) . ' second(s).');
$auth_basic_user = ''; $auth_basic_password = ''; // $auth_method = 'OAuth'; $auth_oauth_consumer_key = ''; $auth_oauth_consumer_secret = ''; $auth_oauth_token = ''; $auth_oauth_secret = ''; // $auth_method = ''; // Override above parameters into you own file: include __DIR__ . '/../../secrets.php'; // // =================================================== //$auth_method = 'Basic'; $osmApi = new OSM_Api(array('url' => OSM_Api::URL_DEV_UK)); if ($auth_method == 'Basic') { _wl(' using Basic auth with user="******"'); $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password)); } else { if ($auth_method == 'OAuth') { _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"'); $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret); $oauth->setAccessToken($auth_oauth_token, $auth_oauth_secret); $osmApi->setCredentials($oauth); } } // http://api06.dev.openstreetmap.org/api/0.6/relation/500 // http://api06.dev.openstreetmap.org/api/0.6/way/8184 // http://api06.dev.openstreetmap.org/api/0.6/node/611571 // get a node
$auth_method = 'Basic'; $auth_basic_user = ''; $auth_basic_password = ''; // $auth_method = 'OAuth'; $auth_oauth_consumer_key = ''; $auth_oauth_consumer_secret = ''; $auth_oauth_token = ''; $auth_oauth_secret = ''; // $auth_method = ''; // Override above parameters into you own file: include __DIR__ . '/../../secrets.php'; // // =================================================== $osmApi = new OSM_Api(array('url' => OSM_Api::URL_DEV_UK)); if ($auth_method == 'Basic') { _wl(' using Basic auth with user="******"'); $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password)); } else { if ($auth_method == 'OAuth') { _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"'); $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret); $oauth->setAccessToken($auth_oauth_token, $auth_oauth_secret); $osmApi->setCredentials($oauth); } } // http://api06.dev.openstreetmap.org/api/0.6/relation/500 // http://api06.dev.openstreetmap.org/api/0.6/way/8184 // http://api06.dev.openstreetmap.org/api/0.6/node/611571 // get a node
--> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" lang="en"></meta> <title>OSM Server Side Script</title> </head> <body> <h1>Overpass-API Query Form</h1> <?php require_once __DIR__ . '/../lib/OSM/Api.php'; /** * You can change the Overpass-API with option 'oapi_url'. * $osmop = new OSM_Api( array( 'oapi_url'=>'http://anotherinterpreter.org' ) ); */ $osmop = new OSM_Api(); $oapiUrl = $osmop->getOption('oapi_url'); ?> <p>A simple proxy to overpass-api using class OSM_Api at <a href="<?php echo $oapiUrl; ?> "><?php echo $oapiUrl; ?> </a><br/> Documentation: <a href="http://wiki.openstreetmap.org/wiki/Overpass_API">Overpass_API</a>, <a href="http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide">Overpass_API/Language_Guide</a> </p> <?php
require_once __DIR__ . '/tests_common.php'; _wl('test "' . basename(__FILE__) . ''); _wl(''); _wl('*** ATTENTION'); _wl('*** ATTENTION : this test work on the production server !'); _wl('*** ATTENTION'); _wl(''); require_once __DIR__ . '/../lib/OSM/Api.php'; // =================================================== // Authentification // // Override above parameters into you own file: include __DIR__ . '/../../secrets_prod.php'; // // =================================================== $osmApi = new OSM_Api(array('simulation' => false)); if ($auth_method == 'Basic') { _wl(' using Basic auth with user="******"'); $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password)); } else { if ($auth_method == 'OAuth') { _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"'); $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret); $oauth->setToken($auth_oauth_token, $auth_oauth_secret); $osmApi->setCredentials($oauth); } } // http://www.openstreetmap.org/api/0.6/node/1326928399 $xmlQuery = ' <osm-script> <query type="node">
$auth_method = 'Basic'; $auth_basic_user = ''; $auth_basic_password = ''; // $auth_method = 'OAuth'; $auth_oauth_consumer_key = ''; $auth_oauth_consumer_secret = ''; $auth_oauth_token = ''; $auth_oauth_secret = ''; // $auth_method = ''; // Override above parameters into you own file: include __DIR__ . '/../../secrets.php'; // // =================================================== $osmApi = new OSM_Api(array('url' => OSM_Api::URL_DEV_UK, 'url4Write' => OSM_Api::URL_DEV_UK, 'simulation' => false)); if ($auth_method == 'Basic') { _wl(' using Basic auth with user="******"'); $osmApi->setCredentials(new OSM_Auth_Basic($auth_basic_user, $auth_basic_password)); } else { if ($auth_method == 'OAuth') { _wl(' using OAuth auth with consumerKey="' . $auth_oauth_consumer_key . '"'); $oauth = new OSM_Auth_OAuth($auth_oauth_consumer_key, $auth_oauth_consumer_secret); $oauth->setToken($auth_oauth_token, $auth_oauth_secret); $osmApi->setCredentials($oauth); } } // http://api06.dev.openstreetmap.org/api/0.6/relation/500 // http://api06.dev.openstreetmap.org/api/0.6/way/8184 // http://api06.dev.openstreetmap.org/api/0.6/node/611571 // get a node
$result = $oauth->http($apiUrl . '/user/details'); echo 'User details: ' . print_r($result, true) . "\n"; // Ask a changeSet (PUT) $xmlStr = "<?xml version='1.0' encoding=\"UTF-8\"?>\n" . '<osm version="0.6" generator="DEV OAUTH">' . '<changeset id="0" open="false">' . '<tag k="created_by" v="DEV OAUTH http://www.openstreetmap.org/user/Cyrille37"/>' . '<tag k="comment" v="test test"/>' . '</changeset></osm>'; $result = $oauth->http($apiUrl . '/changeset/create','PUT', $xmlStr); echo 'Changeset create: ' . print_r($result, true) . "\n"; */ $osmApi = new OSM_Api(array('url' => $apiUrl)); $osmApi->setCredentials($oauth); $userDetails = $osmApi->getUserDetails(); $userDetails = $userDetails->getDetails(); echo print_r($userDetails); } else { echo 'Requesting Authorization...' . "\n"; $authCredentials = $oauth->requestAuthorizationUrl(); $authUrl = $authCredentials['url']; //echo 'Goto "' . $authUrl . '&callback=' . urlencode('http://osm7.openstreetmap.fr/~cgiquello/dummyCallback.php') . '"' . "\n"; echo 'Goto "' . $authUrl . '"' . "\n"; echo 'waiting you coming back ...' . "\n"; flush(); $handle = fopen("php://stdin", "r"); $line = fgets($handle); echo 'Requesting an Access token.' . "\n";
require_once $OSM_Api_filename; // // Let's go ! // // Phase 2 $consumerKey = isset($_REQUEST['consumerKey']) ? $_REQUEST['consumerKey'] : null; $consumerSecret = isset($_REQUEST['consumerSecret']) ? $_REQUEST['consumerSecret'] : null; // Phase 3 $authUrl = null; $authReqToken = isset($_REQUEST['authReqToken']) ? $_REQUEST['authReqToken'] : null; $authReqTokenSecret = isset($_REQUEST['authReqTokenSecret']) ? $_REQUEST['authReqTokenSecret'] : null; $authAccessToken = null; $authAccessTokenSecret = null; if (!empty($consumerKey) && !empty($consumerSecret)) { $oauth = new OSM_Auth_OAuth($consumerKey, $consumerSecret, array('requestTokenUrl' => OSM_Auth_OAuth::REQUEST_TOKEN_URL_DEV, 'accessTokenUrl' => OSM_Auth_OAuth::ACCESS_TOKEN_URL_DEV, 'authorizeUrl' => OSM_Auth_OAuth::AUTHORIZE_TOKEN_URL_DEV)); $osmApi = new OSM_Api(array('url' => OSM_Api::URL_DEV_UK)); $osmApi->setCredentials($oauth); if (empty($authReqToken) && empty($authReqTokenSecret)) { $authCredentials = $oauth->requestAuthorizationUrl(); $authUrl = $authCredentials['url']; $authReqToken = $authCredentials['token']; $authReqTokenSecret = $authCredentials['tokenSecret']; } else { $oauth->setRequestToken($authReqToken, $authReqTokenSecret); $authCredentials = $oauth->requestAccessToken(); $authAccessToken = $authCredentials['token']; $authAccessTokenSecret = $authCredentials['tokenSecret']; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
session_start(); include __DIR__ . '/secrets.php'; $consumer_key = $AUTH_OAUTH_CONSUMER_KEY_DEV; $consumer_secret = $AUTH_OAUTH_CONSUMER_SECRET_DEV; $requestTokenUrl = OSM_Auth_OAuth::REQUEST_TOKEN_URL_DEV; $accessTokenUrl = OSM_Auth_OAuth::ACCESS_TOKEN_URL_DEV; $authorizeUrl = OSM_Auth_OAuth::AUTHORIZE_TOKEN_URL_DEV; $api_url = OSM_Api::URL_DEV_UK; $applicationName = str_replace('.php', '', basename(__FILE__)); _wl('Running ' . $applicationName); // // Create or retreive the OSM_Api instance // if (!isset($_SESSION['api'])) { _wl('Create API instance'); $api = new OSM_Api(array('appName' => $applicationName, 'url' => $api_url)); $api->setCredentials(new OSM_Auth_OAuth($consumer_key, $consumer_secret, array('requestTokenUrl' => $requestTokenUrl, 'accessTokenUrl' => $accessTokenUrl, 'authorizeUrl' => $authorizeUrl, 'callback_url' => 'http://localhost/dev.www/Cartographie/OSM/yapafo/examples/OAuthWebUsage.php'))); $_SESSION['api'] = $api; $oauth = $api->getCredentials(); } else { $api = $_SESSION['api']; $oauth = $api->getCredentials(); } /// Logout if (isset($_REQUEST['deleteAccess'])) { $oauth->deleteAccessAuthorization(); } // If a callback url has been set for consumer application, // the user will come back here after authorization acceptation. // The osm site will callback us with the parameter "oauth_token" if (isset($_REQUEST['oauth_token'])) {