{"__v":10,"_id":"53fe7df4addab8973c1af2b7","category":{"__v":5,"_id":"53fe7d8daddab8973c1af2b1","pages":["53fe732eaddab8973c1af27f","53fe7df4addab8973c1af2b7","53fe7e08addab8973c1af2b9","544945633acc37080099e719","551c450c0360770d00f5ce3a"],"project":"53fe6dc5addab8973c1af267","version":"53fe6dc5addab8973c1af26a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-08-28T00:53:33.662Z","from_sync":false,"order":5,"slug":"login-reference","title":"Login Reference"},"comments":[],"is_link":false,"parentDoc":null,"project":"53fe6dc5addab8973c1af267","tags":[],"user":"53fe6d8baddab8973c1af266","version":{"__v":19,"_id":"53fe6dc5addab8973c1af26a","project":"53fe6dc5addab8973c1af267","createdAt":"2014-08-27T23:46:13.941Z","releaseDate":"2014-08-27T23:46:13.941Z","categories":["53fe6dc5addab8973c1af26b","53fe71a2addab8973c1af276","53fe7d89addab8973c1af2b0","53fe7d8daddab8973c1af2b1","53fe836faddab8973c1af2ce","53ff9a4823a37e1d5cebafe1","53ff9e3723a37e1d5cebaff7","53ffaca523a37e1d5cebb039","53ffad2e23a37e1d5cebb03c","5400c7d2ec93b29b61d4f7be","5400f0e1ec93b29b61d4f7dd","54d5636323010a0d001aca81","54d565c1276f8e0d00feab54","54ff40532882a10d00546927","556606d25561af0d008208b7","558c91900b236c2500d37c9a","56180a14f8c9632100ac7599","564fb3a59b4fab1700187518","5702e2d2f2d6f336005e901f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["5561d3154bfe45170030a033"],"next":{"pages":[],"description":""},"createdAt":"2014-08-28T00:55:16.900Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"basic_auth":false,"results":{"codes":[]},"settings":"","try":true,"auth":"never","params":[],"url":""},"isReference":false,"order":1,"body":"# Requesting user information\n\nNow that you have an access token, you can get all the user information you need from the Clef API. It's as simple as hitting a single API route.\n\nThe sample code below shows how to exchange an access token for user information.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"require 'httparty'\\nrequire 'json'\\n\\nbase_url = \\\"https://clef.io/api/v1/info\\\"\\nquery_string = \\\"?access_token=#{access_token}\\\"\\nurl = base_url + query_string\\n\\nresponse = HTTParty.get(url)\\n\\nif response['success']\\n    user_info = response\\n    # {\\n    #   info: {\\n    #     id: '12345',\\n    #     first_name: 'Jesse',\\n    #     last_name: 'Pollak',\\n    #     phone_number: '1234567890',\\n    #     email: 'jesse:::at:::getclef.com'\\n    #   },\\n    #   success: true\\n    # }\\nelse\\n    p response['error']\\nend\\n           \",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"import requests\\nimport json\\n\\nbase_url = 'https://clef.io/api/v1/info'\\nquery_string = '?access_token=%s' % access_token\\nurl = base_url + query_string\\n\\nresponse = requests.get(url)\\njson_response = json.loads(response.text)\\n\\nif json_response.get('success', False):\\n    user_info = json_response\\n    # {\\n    #   info: {\\n    #     id: '12345',\\n    #     first_name: 'Jesse',\\n    #     last_name: 'Pollak',\\n    #     phone_number: '1234567890',\\n    #     email: 'jesse@getclef.com'\\n    #   },\\n    #   success: true\\n    # }\\nelse:\\n    print json_response['error']\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"<?php\\n\\n$opts = array('http' =>\\n            array(\\n                'method'  => 'GET'\\n            )\\n        );\\n\\n$base_url = 'https://clef.io/api/v1/info';\\n$query_string = '?access_token='.$access_token;\\n$url = $base_url.$query_string;\\n\\n$context  = stream_context_create($opts);\\n$response = file_get_contents($url, false, $context);\\n$response = json_decode($response, true);\\n\\nif ($response && $response['success']) {\\n    $user_info = $response['info'];\\n    // $response = {\\n    //   info: {\\n    //     id: '12345',\\n    //     first_name: 'Jesse',\\n    //     last_name: 'Pollak',\\n    //     phone_number: '1234567890',\\n    //     email: 'jesse@getclef.com'\\n    //   },\\n    //   success: true\\n    // }\\n} else {\\n    echo $response['error'];\\n}\\n\\n?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Need some help getting started?\",\n  \"body\": \"We've prepared sample apps for Ruby, Python, PHP, Node and Rails, which you can clone and use as starter code for your application. Get them [here](https://github.com/clef?query=sample).\"\n}\n[/block]\n# Next up\nWith user information in hand, you can [associate Clef logins](/v1.0/docs/persisting-users) with users in your database.\n\n[block:html]\n{\n  \"html\": \"<div></div>\\n<a class=\\\"clef-button blue\\\" href=\\\"/v1.0/docs/persisting-users\\\">Go to the next section</a>\\n<style></style>\"\n}\n[/block]","excerpt":"With an access token in hand, you can get identifying user data with one API request.","slug":"accessing-user-information","type":"basic","title":"Accessing user information"}

Accessing user information

With an access token in hand, you can get identifying user data with one API request.

# Requesting user information Now that you have an access token, you can get all the user information you need from the Clef API. It's as simple as hitting a single API route. The sample code below shows how to exchange an access token for user information. [block:code] { "codes": [ { "code": "require 'httparty'\nrequire 'json'\n\nbase_url = \"https://clef.io/api/v1/info\"\nquery_string = \"?access_token=#{access_token}\"\nurl = base_url + query_string\n\nresponse = HTTParty.get(url)\n\nif response['success']\n user_info = response\n # {\n # info: {\n # id: '12345',\n # first_name: 'Jesse',\n # last_name: 'Pollak',\n # phone_number: '1234567890',\n # email: 'jesse@getclef.com'\n # },\n # success: true\n # }\nelse\n p response['error']\nend\n ", "language": "ruby" }, { "code": "import requests\nimport json\n\nbase_url = 'https://clef.io/api/v1/info'\nquery_string = '?access_token=%s' % access_token\nurl = base_url + query_string\n\nresponse = requests.get(url)\njson_response = json.loads(response.text)\n\nif json_response.get('success', False):\n user_info = json_response\n # {\n # info: {\n # id: '12345',\n # first_name: 'Jesse',\n # last_name: 'Pollak',\n # phone_number: '1234567890',\n # email: 'jesse@getclef.com'\n # },\n # success: true\n # }\nelse:\n print json_response['error']", "language": "python" }, { "code": "<?php\n\n$opts = array('http' =>\n array(\n 'method' => 'GET'\n )\n );\n\n$base_url = 'https://clef.io/api/v1/info';\n$query_string = '?access_token='.$access_token;\n$url = $base_url.$query_string;\n\n$context = stream_context_create($opts);\n$response = file_get_contents($url, false, $context);\n$response = json_decode($response, true);\n\nif ($response && $response['success']) {\n $user_info = $response['info'];\n // $response = {\n // info: {\n // id: '12345',\n // first_name: 'Jesse',\n // last_name: 'Pollak',\n // phone_number: '1234567890',\n // email: 'jesse@getclef.com'\n // },\n // success: true\n // }\n} else {\n echo $response['error'];\n}\n\n?>", "language": "php" } ] } [/block] [block:callout] { "type": "info", "title": "Need some help getting started?", "body": "We've prepared sample apps for Ruby, Python, PHP, Node and Rails, which you can clone and use as starter code for your application. Get them [here](https://github.com/clef?query=sample)." } [/block] # Next up With user information in hand, you can [associate Clef logins](/v1.0/docs/persisting-users) with users in your database. [block:html] { "html": "<div></div>\n<a class=\"clef-button blue\" href=\"/v1.0/docs/persisting-users\">Go to the next section</a>\n<style></style>" } [/block]