{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/vi/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Ví dụ về điện thoại đám mây","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"ví-dụ-về-điện-thoại-đám-mây","__idx":0},"children":["Ví dụ về điện thoại đám mây"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Hoàn thành các ví dụ hoạt động để quản lý điện thoại trên đám mây bằng API mở."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["URL cơ sở"]},": ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.morelogin.com"]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"quy-trình-làm-việc-đầy-đủ-xác-thực--tạo--cài-đặt-ứng-dụng--adb","__idx":1},"children":["Quy trình làm việc đầy đủ: Xác thực → Tạo → Cài đặt ứng dụng → ADB"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"cuộn-tròn","__idx":2},"children":["cuộn tròn"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"# 1. Get access token\nTOKEN=$(curl -s -X POST https://api.morelogin.com/oauth2/token \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"client_id\": \"YOUR_API_ID\",\n    \"client_secret\": \"YOUR_API_KEY\",\n    \"grant_type\": \"client_credentials\"\n  }' | jq -r '.data.access_token')\n\necho \"Token: $TOKEN\"\n\n# 2. Create a cloud phone\ncurl -X POST https://api.morelogin.com/cloudphone/create \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -d '{\n    \"name\": \"my-cloud-phone\",\n    \"areaId\": 1,\n    \"groupId\": \"your-group-id\"\n  }'\n\n# 3. Start the cloud phone\ncurl -X POST https://api.morelogin.com/cloudphone/start \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -d '{\"ids\": [\"CLOUD_PHONE_ID\"]}'\n\n# 4. Install an app\ncurl -X POST https://api.morelogin.com/cloudphone/app/install \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -d '{\n    \"id\": CLOUD_PHONE_ID,\n    \"packageName\": \"com.example.app\",\n    \"versionCode\": 1\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"python-yêu-cầu","__idx":3},"children":["Python (yêu cầu)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import requests\n\nBASE = \"https://api.morelogin.com\"\nAPI_ID = \"YOUR_API_ID\"\nAPI_KEY = \"YOUR_API_KEY\"\n\n# 1. Get access token\nresp = requests.post(f\"{BASE}/oauth2/token\", json={\n    \"client_id\": API_ID,\n    \"client_secret\": API_KEY,\n    \"grant_type\": \"client_credentials\"\n})\ntoken = resp.json()[\"data\"][\"access_token\"]\nheaders = {\"Authorization\": f\"Bearer {token}\"}\nprint(f\"Token acquired (expires in {resp.json()['data']['expires_in']}s)\")\n\n# 2. Create a cloud phone\nresp = requests.post(f\"{BASE}/cloudphone/create\", headers=headers, json={\n    \"name\": \"automation-phone\",\n    \"areaId\": 1,\n    \"groupId\": \"your-group-id\"\n})\nphone_id = resp.json()[\"data\"][\"id\"]\nprint(f\"Created cloud phone: {phone_id}\")\n\n# 3. Start the cloud phone\nresp = requests.post(f\"{BASE}/cloudphone/start\", headers=headers, json={\n    \"ids\": [str(phone_id)]\n})\nprint(f\"Start result: {resp.json()['code']}\")\n\n# 4. Install app\nresp = requests.post(f\"{BASE}/cloudphone/app/install\", headers=headers, json={\n    \"id\": phone_id,\n    \"packageName\": \"com.example.app\",\n    \"versionCode\": 1\n})\nprint(f\"App install: {resp.json()['code']}\")\n\n# 5. Enable ADB\nresp = requests.post(f\"{BASE}/cloudphone/enableAdb\", headers=headers, json={\n    \"id\": phone_id\n})\nadb_info = resp.json()[\"data\"]\nprint(f\"ADB enabled - connect with: adb connect {adb_info.get('host')}:{adb_info.get('port')}\")\n\n# 6. Stop cloud phone when done\nresp = requests.post(f\"{BASE}/cloudphone/stop\", headers=headers, json={\n    \"ids\": [str(phone_id)]\n})\nprint(\"Cloud phone stopped.\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"nodejs-axios","__idx":4},"children":["Node.js (axios)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const axios = require('axios');\n\nconst BASE = 'https://api.morelogin.com';\nconst API_ID = 'YOUR_API_ID';\nconst API_KEY = 'YOUR_API_KEY';\n\nasync function main() {\n  // 1. Get access token\n  const authResp = await axios.post(`${BASE}/oauth2/token`, {\n    client_id: API_ID,\n    client_secret: API_KEY,\n    grant_type: 'client_credentials'\n  });\n  const token = authResp.data.data.access_token;\n  const headers = { Authorization: `Bearer ${token}` };\n  console.log('Token acquired');\n\n  // 2. Create a cloud phone\n  const createResp = await axios.post(`${BASE}/cloudphone/create`,\n    { name: 'automation-phone', areaId: 1 },\n    { headers }\n  );\n  const phoneId = createResp.data.data.id;\n  console.log(`Created cloud phone: ${phoneId}`);\n\n  // 3. Start cloud phone\n  await axios.post(`${BASE}/cloudphone/start`,\n    { ids: [String(phoneId)] },\n    { headers }\n  );\n  console.log('Cloud phone started');\n\n  // 4. Install app\n  await axios.post(`${BASE}/cloudphone/app/install`,\n    { id: phoneId, packageName: 'com.example.app', versionCode: 1 },\n    { headers }\n  );\n  console.log('App installation initiated');\n\n  // 5. Enable ADB\n  const adbResp = await axios.post(`${BASE}/cloudphone/enableAdb`,\n    { id: phoneId },\n    { headers }\n  );\n  console.log('ADB enabled:', adbResp.data.data);\n\n  // 6. Stop when done\n  await axios.post(`${BASE}/cloudphone/stop`,\n    { ids: [String(phoneId)] },\n    { headers }\n  );\n  console.log('Cloud phone stopped');\n}\n\nmain().catch(console.error);\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"ví-dụ-tải-lên-tệp-python","__idx":5},"children":["Ví dụ tải lên tệp (Python)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import requests\n\nBASE = \"https://api.morelogin.com\"\nheaders = {\"Authorization\": \"Bearer YOUR_TOKEN\"}\n\nphone_id = 1234567890\n\n# 1. Get presigned upload URL\nresp = requests.post(f\"{BASE}/cloudphone/uploadUrl\", headers=headers, json={\n    \"id\": phone_id,\n    \"fileName\": \"config.json\"\n})\nupload_url = resp.json()[\"data\"][\"presignedUrl\"]\n\n# 2. Upload file to presigned URL\nwith open(\"config.json\", \"rb\") as f:\n    requests.put(upload_url, data=f)\n\n# 3. Trigger file upload to cloud phone\nresp = requests.post(f\"{BASE}/cloudphone/uploadFile\", headers=headers, json={\n    \"id\": str(phone_id),\n    \"url\": upload_url,\n    \"uploadDest\": \"/Download\"\n})\nfile_id = resp.json()[\"data\"][\"fileId\"]\n\n# 4. Check upload result\nresp = requests.post(f\"{BASE}/cloudphone/uploadFileResult\", headers=headers, json={\n    \"id\": str(phone_id),\n    \"fileId\": file_id\n})\nprint(f\"Upload status: {resp.json()['data']['status']}\")  # 1 = success\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"ví-dụ-sdk-python-hoàn-chỉnh","__idx":6},"children":["Ví dụ SDK Python hoàn chỉnh"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Các đoạn mã trên minh họa các lệnh gọi API riêng lẻ. Để có ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["lớp máy khách Python sẵn sàng cho sản xuất"]}," với quản lý token tự động, nhóm kết nối và các thao tác vòng đời thiết bị hoàn chỉnh, hãy xem ví dụ hoàn chỉnh trên GitHub:"]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["📦 ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/MoreLoginBrowser/MoreLogin-API-Demos/blob/main/MoreLogin-Python/cloud_phone/cloud_phone_open_api_demo.py"},"children":["GitHub — cloud_phone_open_api_demo.py"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Bao gồm:"]}]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Tính năng"},"children":["Tính năng"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Mô tả"},"children":["Mô tả"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Tự động làm mới token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Tự động lấy và làm mới token truy cập 60 giây trước khi hết hạn"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Nhóm kết nối"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Sử dụng ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requests.Session"]}," với kích thước pool có thể cấu hình cho các tình huống thông lượng cao"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Quản lý thiết bị"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Danh sách thiết bị, thông tin thiết bị, truy vấn theo Android ID"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Quản lý nguồn"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Bật / tắt điện thoại đám mây với tùy chọn gán proxy"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Quản lý ứng dụng"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Cài đặt, khởi chạy, dừng, khởi động lại, gỡ cài đặt ứng dụng"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Quản lý tệp"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Tải lên và tải xuống tệp từ điện thoại đám mây"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Proxy và nhóm"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Quản lý proxy và nhóm thông qua Open API"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Sử dụng nhanh:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from cloud_phone_open_api_demo import MoreLoginCloudPhone\n\nclient = MoreLoginCloudPhone(app_id=\"YOUR_APP_ID\", api_key=\"YOUR_API_KEY\")\n\n# Liệt kê tất cả điện thoại đám mây\ndevices = client.list_devices()\nprint(devices)\n\n# Lấy thông tin thiết bị\ninfo = client.get_device_info(phone_id=1234567890)\nprint(info)\n\n# Bật điện thoại đám mây\nclient.power_on(phone_id=1234567890)\n","lang":"python"},"children":[]}]},"headings":[{"value":"Ví dụ về điện thoại đám mây","id":"ví-dụ-về-điện-thoại-đám-mây","depth":1},{"value":"Quy trình làm việc đầy đủ: Xác thực → Tạo → Cài đặt ứng dụng → ADB","id":"quy-trình-làm-việc-đầy-đủ-xác-thực--tạo--cài-đặt-ứng-dụng--adb","depth":2},{"value":"cuộn tròn","id":"cuộn-tròn","depth":3},{"value":"Python (yêu cầu)","id":"python-yêu-cầu","depth":3},{"value":"Node.js (axios)","id":"nodejs-axios","depth":3},{"value":"Ví dụ tải lên tệp (Python)","id":"ví-dụ-tải-lên-tệp-python","depth":2},{"value":"Ví dụ SDK Python hoàn chỉnh","id":"ví-dụ-sdk-python-hoàn-chỉnh","depth":2}],"frontmatter":{"seo":{"title":"Ví dụ về điện thoại đám mây"}},"lastModified":"2026-06-17T03:35:58.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/vi/api-reference/examples/cloudphone-examples","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}