{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Sign in with an existing account","type":"basic","slug":"sign-in-with-an-existing-account","excerpt":"[See on github](https://github.com/badoualy/kotlogram/blob/master/sample/src/main/java/com/github/badoualy/telegram/sample/SampleSignIn.java)","body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// This is a synchronous client, that will block until the response arrive (or until timeout)\\nTelegramClient client = Kotlogram.getDefaultClient(application, new ApiStorage());\\n\\n// You can start making requests\\ntry {\\n    // Send code to account\\n    TLSentCode sentCode = client.authSendCode(false, PHONE_NUMBER, true);\\n    System.out.println(\\\"Authentication code: \\\");\\n    String code = new Scanner(System.in).nextLine();\\n\\n    // Auth with the received code\\n    TLAuthorization authorization = client.authSignIn(PHONE_NUMBER, sentCode.getPhoneCodeHash(), code);\\n    TLUser self = authorization.getUser().getAsUser();\\n    System.out.println(\\\"You are now signed in as \\\" + self.getFirstName() + \\\" \\\" + self.getLastName() + \\\" :::at:::\\\" + self.getUsername());\\n} catch (RpcErrorException | IOException e) {\\n    e.printStackTrace();\\n} finally {\\n    client.close(); // Important, do not forget this, or your process won't finish\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5703e4e4aceacc17003ef332","createdAt":"2016-04-05T16:16:36.748Z","version":{"version":"0.0.6","version_clean":"0.0.6","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["5703d527bb69fc1700553ce4","5703d8b7aceacc17003ef303","5703e60b6116142000db25f6","57e0db616a1c2e0e0081fe64","57e0f141ff540c22007b45fa","57e0f14b8929550e00f1d9bc"],"_id":"5703d527bb69fc1700553ce3","createdAt":"2016-04-05T15:09:27.620Z","hasDoc":true,"releaseDate":"2016-04-05T15:09:27.620Z","__v":6,"hasReference":true,"project":"5703d527bb69fc1700553ce0"},"parentDoc":null,"githubsync":"","user":"5631f962c3b04b0d00ba9bf1","__v":1,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Samples","slug":"samples","order":1,"from_sync":false,"reference":false,"_id":"5703d8b7aceacc17003ef303","version":"5703d527bb69fc1700553ce3","createdAt":"2016-04-05T15:24:39.108Z","__v":0,"project":"5703d527bb69fc1700553ce0"},"project":"5703d527bb69fc1700553ce0"}

Sign in with an existing account

[See on github](https://github.com/badoualy/kotlogram/blob/master/sample/src/main/java/com/github/badoualy/telegram/sample/SampleSignIn.java)

[block:code] { "codes": [ { "code": "// This is a synchronous client, that will block until the response arrive (or until timeout)\nTelegramClient client = Kotlogram.getDefaultClient(application, new ApiStorage());\n\n// You can start making requests\ntry {\n // Send code to account\n TLSentCode sentCode = client.authSendCode(false, PHONE_NUMBER, true);\n System.out.println(\"Authentication code: \");\n String code = new Scanner(System.in).nextLine();\n\n // Auth with the received code\n TLAuthorization authorization = client.authSignIn(PHONE_NUMBER, sentCode.getPhoneCodeHash(), code);\n TLUser self = authorization.getUser().getAsUser();\n System.out.println(\"You are now signed in as \" + self.getFirstName() + \" \" + self.getLastName() + \" @\" + self.getUsername());\n} catch (RpcErrorException | IOException e) {\n e.printStackTrace();\n} finally {\n client.close(); // Important, do not forget this, or your process won't finish\n}", "language": "java" } ] } [/block]