{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/zh/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"云手机示例","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":"云手机示例","__idx":0},"children":["云手机示例"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["使用开放 API 进行云手机管理的完整工作示例。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["基本网址"]},"：",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.morelogin.com"]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"完整工作流程身份验证创建安装应用程序adb","__idx":1},"children":["完整工作流程：身份验证→创建→安装应用程序→ADB"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"curl","__idx":2},"children":["curl"]},{"$$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请求","__idx":3},"children":["Python（请求）"]},{"$$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":"nodejsaxios","__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":"文件上传示例python","__idx":5},"children":["文件上传示例（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":[]}]},"headings":[{"value":"云手机示例","id":"云手机示例","depth":1},{"value":"完整工作流程：身份验证→创建→安装应用程序→ADB","id":"完整工作流程身份验证创建安装应用程序adb","depth":2},{"value":"curl","id":"curl","depth":3},{"value":"Python（请求）","id":"python请求","depth":3},{"value":"Node.js（axios）","id":"nodejsaxios","depth":3},{"value":"文件上传示例（Python）","id":"文件上传示例python","depth":2}],"frontmatter":{"seo":{"title":"云手机示例"}},"lastModified":"2026-06-10T11:47:34.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zh/api-reference/examples/cloudphone-examples","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}