$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"; $authCredentials = $oauth->requestAccessToken();
$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 $permissions = $osmApi->getAuthPermissions(); echo print_r($permissions, true) . "\n"; if ($auth_method == 'Basic') {
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'])) { _wl('User coming back via callback url.');