ตัวอย่าง: แชร์ข้อมูลเข้าสู่ระบบกับหลายเว็บไซต์และแอป Android หลายแอป
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หากต้องการตั้งค่าการแชร์ข้อมูลเข้าสู่ระบบในเว็บไซต์และแอป Android หลายรายการ คุณต้องมีคุณสมบัติดังนี้
- กำหนดโดเมนหลัก: เลือก URL 1 รายการเป็นจุดอ้างอิงหลักสำหรับลิงก์
- สร้าง
assetlinks.json
ไฟล์
- โดเมนหลัก: สร้างไฟล์
assetlinks.json
ในโดเมนหลักซึ่งแสดงโดเมนทั้งหมดที่แชร์ข้อมูลเข้าสู่ระบบ
- โดเมนอื่นๆ: สร้างไฟล์
assetlinks.json
บนโดเมนอื่นๆ แต่ละโดเมน โดยแต่ละโดเมนลิงก์กลับไปยังโดเมนหลัก
- กำหนดค่าการลิงก์เนื้อหาดิจิทัลในไฟล์ Manifest ของแอปแต่ละรายการ: ตั้งค่าแต่ละแอปให้ลิงก์กลับไปยังไฟล์
assetlinks.json
ในโดเมนหลัก
ในตัวอย่างนี้ เรากำหนด example.com เป็นโดเมนหลัก และโดเมนอื่นๆ ทั้งหมดที่แสดงจะแชร์ข้อมูลเข้าสู่ระบบกับ example.com และกับโดเมนอื่นๆ เอง
แอป 2 แอปที่มีชื่อแพ็กเกจต่อไปนี้จะแชร์ข้อมูลเข้าสู่ระบบกับเว็บไซต์ทั้งหมดและระหว่างกันด้วย
com.example.android.myapplication
com.example.appname
ก่อนตั้งค่าการแชร์ข้อมูลเข้าสู่ระบบ คุณต้องทำตามข้อกําหนดเบื้องต้นให้เสร็จสิ้น
วิธีประกาศการแชร์ข้อมูลเข้าสู่ระบบในเว็บไซต์และแอป Android เหล่านี้
สร้างไฟล์ assetlinks.json
ที่มีเนื้อหาต่อไปนี้
[
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.com"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.org"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.net"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://myownpersonaldomain.com"
}
},
{
"relation" : [
"delegate_permission/common.get_login_creds"
],
"target" : {
"namespace" : "android_app",
"package_name" : "com.example.android.myapplication",
"sha256_cert_fingerprints" : [ "AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00:AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00"
]
}
},
{
"relation" : [
"delegate_permission/common.get_login_creds"
],
"target" : {
"namespace" : "android_app",
"package_name" : "com.example.appname",
"sha256_cert_fingerprints" : [ "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF"
]
}
}
]
โฮสต์ไฟล์ JSON ของลิงก์เนื้อหาดิจิทัล (Digital Asset Links) ในตำแหน่งที่รู้จักซึ่งสอดคล้องกับโดเมนหลัก ในกรณีนี้https://example.com/.well-known/assetlinks.json
สร้างไฟล์ assetlinks.json
ไฟล์อื่นที่มีเนื้อหาต่อไปนี้
[
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "example.com"
}
}
]
ในกรณีนี้ โปรดโฮสต์สำเนาของไฟล์ JSON ของลิงก์เนื้อหาดิจิทัล (Digital Asset Links) ที่ตำแหน่งต่อไปนี้ในโดเมนอื่นๆ
example.org/.well-known/assetlinks.json
example.net/.well-known/assetlinks.json
mypersonaldomain.com/.well-known/assetlinks.json
เพิ่มบรรทัดต่อไปนี้ลงในไฟล์ Manifest ของแอป Android ทั้ง 2 ไฟล์ในส่วน
<application>
<meta-data android:name="asset_statements" android:resource="@string/asset_statements"/>
กำหนดค่าการลิงก์เนื้อหาดิจิทัลในไฟล์ Manifest ด้วยการประกาศการเชื่อมโยงในแอป Android เพิ่มออบเจ็กต์ที่ระบุไฟล์ assetlinks.json
ที่จะโหลด ในกรณีนี้
<string name="asset_statements" translatable="false">
[{
\"include\": \"https://example.com/.well-known/assetlinks.json\"
}]
</string>
หลังจากทำตามขั้นตอนเหล่านี้ คุณได้ตั้งค่าการแชร์ข้อมูลเข้าสู่ระบบในเว็บไซต์และแอป Android หลายรายการอย่างราบรื่นแล้ว
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["# Example: Share credentials across multiple websites and multiple Android apps\n\nTo set up credential sharing across multiple websites and multiple Android apps\nyou must:\n\n- **Designate a primary domain**: Choose one URL as the primary reference point for links.\n- **Create `assetlinks.json` files** :\n - **Primary domain** : Create an `assetlinks.json` file on your primary domain that lists all domains sharing credentials.\n - **Other domains** : Create an `assetlinks.json` file on each of the other domains, each linking back to the primary domain.\n- **Configure digital asset linking in each App's manifest** : Set up each app to link back to the `assetlinks.json` file in the primary domain.\n\n| **Important:** While Google treats credential sharing relationships as transitive, individual [Digital Asset Links are\n| not](https://developers.google.com/digital-asset-links/reference/rpc/google.digitalassetlinks.v1).\n\nIn the following example, we designated\n[example.com](https://example.com/) as the primary domain, and all other\nlisted domains share credentials with\n[example.com](https://example.com/) and across themselves.\n\n- [example.com](https://example.com/) (primary domain)\n- [example.org](https://example.jp/)\n- [example.net](https://example.de/)\n- [myownpersonaldomain.com](http://myownpersonaldomain.com)\n\nThe two apps with the following package names also share credentials with all\nthe websites and between them:\n\n- `com.example.android.myapplication`\n- `com.example.appname`\n\nBefore setting up credential sharing you must [complete the prerequisites](/identity/credential-sharing/set-up#prerequisites).\n\nTo declare credential sharing across these websites and Android apps:\n\n1. Create an `assetlinks.json` file with the following content:\n\n [\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.com\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.org\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.net\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://myownpersonaldomain.com\"\n }\n },\n {\n \"relation\" : [\n \"delegate_permission/common.get_login_creds\"\n ],\n \"target\" : {\n \"namespace\" : \"android_app\",\n \"package_name\" : \"com.example.android.myapplication\",\n \"sha256_cert_fingerprints\" : [ \"AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00:AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00\"\n ]\n }\n },\n {\n \"relation\" : [\n \"delegate_permission/common.get_login_creds\"\n ],\n \"target\" : {\n \"namespace\" : \"android_app\",\n \"package_name\" : \"com.example.appname\",\n \"sha256_cert_fingerprints\" : [ \"00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF\"\n ]\n }\n }\n ]\n\n2. Host the Digital Asset Links JSON file in the corresponding well-known\n location on the primary domain, in this case:\n `https://example.com/.well-known/assetlinks.json`.\n\n3. Create another `assetlinks.json` file with the following content:\n\n [\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"example.com\"\n }\n }\n ]\n\n4. Host copies of this Digital Asset Links JSON file at the following location\n on the other domains, in this case:\n\n - `example.org/.well-known/assetlinks.json`\n - `example.net/.well-known/assetlinks.json`\n - `mypersonaldomain.com/.well-known/assetlinks.json`\n5. Add the following line to both Android Apps manifests files under\n `\u003capplication\u003e`:\n\n \u003cmeta-data android:name=\"asset_statements\" android:resource=\"@string/asset_statements\"/\u003e\n\n6. Configure digital asset linking in the manifest by declaring the association\n in the Android app. Add an object that specifies the `assetlinks.json` files\n to load. In this case:\n\n \u003cstring name=\"asset_statements\" translatable=\"false\"\u003e\n [{\n \\\"include\\\": \\\"https://example.com/.well-known/assetlinks.json\\\"\n }]\n \u003c/string\u003e\n\nAfter following these steps, you have successfully set up seamless credential\nsharing across multiple websites and Android apps."]]