$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 $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);
* en étape 2 pour accéder aux données de l'utilisateur. * * Note: files "secrets.php" and "test_OSM_OAuth.php.token" are ignored by Git (see .gitignore) */ $DEV = true; $time_start = microtime(true); require_once __DIR__ . '/tests_common.php'; _wl('test "' . basename(__FILE__) . ''); 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)