//
$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
$permissions = $osmApi->getAuthPermissions();
echo print_r($permissions, true) . "\n";
if ($auth_method == 'Basic') {
    _assert($osmApi->isAllowedToReadPrefs() === true);
    _assert($osmApi->isAllowedToWritePrefs() === true);
    _assert($osmApi->isAllowedToWriteDiary() === true);
    _assert($osmApi->isAllowedToWriteApi() === true);
    _assert($osmApi->isAllowedToReadGpx() === true);
示例#2
0
require_once __DIR__ . '/../lib/OSM/Api.php';
include_once __DIR__ . '/secrets.php';
if ($DEV) {
    $apiUrl = 'http://api06.dev.openstreetmap.org/api/0.6';
    $oauth = new OSM_Auth_OAuth($AUTH_OAUTH_CONSUMER_KEY_DEV, $AUTH_OAUTH_CONSUMER_SECRET_DEV, 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));
} else {
    $apiUrl = 'http://www.openstreetmap.org/api/0.6';
    $oauth = new OSM_Auth_OAuth($AUTH_OAUTH_CONSUMER_KEY_PROD, $AUTH_OAUTH_CONSUMER_SECRET_PROD);
}
$tokenFilename = __DIR__ . '/' . basename(__FILE__) . '.token';
if (file_exists($tokenFilename)) {
    echo 'Reusing Authorization...' . "\n";
    $fp = fopen($tokenFilename, 'r');
    eval('$authCredentials = ' . file_get_contents($tokenFilename) . ';');
    fclose($fp);
    $oauth->setAccessToken($authCredentials['token'], $authCredentials['tokenSecret']);
    /*
    	// Get user details (GET)
    
    	$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);