عيّنات من الروابط إلى مواد العرض الرقمية من Google
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
غالبًا ما يكون نموذج الرمز البرمجي هو أسهل طريقة للتعرّف على كيفية استخدام واجهة برمجة التطبيقات. للحصول على روابط
إلى نماذج روابط Google Digital Asset Links، اختَر لغة برمجة أدناه.
إذا لم تتضمن صفحة نماذج مكتبة ما نموذجًا
روابط مواد العرض الرقمية من Google، لا يزال بإمكانك استخدام تلك المكتبة وقد يكون بإمكانك
لتكييف النماذج المتوفرة مع واجهة برمجة تطبيقات مختلفة من Google.
Python
في ما يلي مثال بسيط على لغة Python يسرد جميع الجمل
التي أدلى بها موقع إلكتروني معيّن، ثم يتحقّق مما إذا كان هذا الموقع الإلكتروني يعرض
عبارة delegate_permission/common.handle_all_urls
عن تطبيق Android معيّن.
في ما يلي مثال بسيط على JavaScript يتيح لك إدراج جميع العبارات التي أدلى بها موقع إلكتروني معيّن
والتحقّق أيضًا من توفّر عبارة معيّنة في ذلك الموقع الإلكتروني.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis page provides code samples in Python and JavaScript demonstrating how to use the Google Digital Asset Links API.\u003c/p\u003e\n"],["\u003cp\u003eThe samples show how to list all statements made by a website and check for specific statements related to Android apps.\u003c/p\u003e\n"],["\u003cp\u003eBefore running the samples, you need to activate the \u003ccode\u003edigitalassetlinks\u003c/code\u003e API for your project and replace \u003ccode\u003eAPI_KEY\u003c/code\u003e with your own API key.\u003c/p\u003e\n"],["\u003cp\u003eWhile Go, Java, .NET, Objective-C, PHP, and Ruby samples aren't specifically provided for this API version, you might be able to adapt existing samples from those languages.\u003c/p\u003e\n"]]],[],null,["# Google Digital Asset Links Samples\n\nSample code is often the easiest way to learn how to use an API. For links\nto Google Digital Asset Links samples, select a programming language below.\n\nThe samples use the Google API [client libraries](/digital-asset-links/v1/libraries).\n\nIf a library's samples page does not yet include a sample for the\nGoogle Digital Asset Links, you can still use that library, and you might be able\nto adapt samples that are provided for a different Google API. \n\n### Python\n\nHere is a simple Python example that lists all statements\nmade by a given website, then checks whether that site makes\nthe `delegate_permission/common.handle_all_urls` statement\nabout a specific Android app.\nIn order to use this code sample, you first need to activate the `digitalassetlinks` API for your project, and you need to replace the string `API_KEY` below with your own API key. See [these instructions](/digital-asset-links/v1/consuming#validating_using_the_api) if you are unfamiliar with the process. \n\n```python\n#!/usr/bin/python\n\nimport urllib\n\ndef ListWeb(source_web_site, relation):\n return urllib.urlopen(\n 'https://digitalassetlinks.googleapis.com/v1/'\n 'statements:list?source.web.site=%s&relation=%s'\n % (urllib.quote(source_web_site, ''),\n urllib.quote(relation, ''))).read()\n\ndef CheckWebToAndroid(source_web_site, relation,\n target_package_name, target_sha256_fingerprint):\n return urllib.urlopen(\n 'https://digitalassetlinks.googleapis.com/v1/'\n 'assetlinks:check?source.web.site=%s&relation=%s'\n '&target.android_app.package_name=%s'\n '&target.android_app.certificate.sha256_fingerprint=%s'\n '&key=API_KEY'\n % (urllib.quote(source_web_site, ''),\n urllib.quote(relation, ''),\n urllib.quote(target_package_name, ''),\n urllib.quote(target_sha256_fingerprint, ''))).read()\n\ndef main():\n print '================================== List() Output ======='\n print ListWeb('http://example.digitalassetlinks.org',\n 'delegate_permission/common.handle_all_urls')\n print '================================== Check() Output ======'\n print CheckWebToAndroid(\n 'http://example.digitalassetlinks.org',\n 'delegate_permission/common.handle_all_urls',\n 'org.digitalassetlinks.sampleapp',\n '10:39:38:EE:45:37:E5:9E:8E:E7:92:F6:54:50:4F:B8:34:6F:C6:B3:46:D0:BB:C4:41:5F:C3:39:FC:FC:8E:C1')\n\nif __name__ == '__main__':\n main()\n```\n\n### JavaScript\n\nHere is a simple JavaScript example that lets you list all statements made by a given website\nand also check for the presence of a given statement in that website.\nIn order to use this code sample, you first need to activate the `digitalassetlinks` API for your project, and you need to replace the string `API_KEY` below with your own API key. See [these instructions](/digital-asset-links/v1/consuming#validating_using_the_api) if you are unfamiliar with the process. \n\n```javascript\n\u003chtml\u003e\n \u003chead\u003e\n \u003cscript type=\"text/javascript\"\u003e\n function executeRequest(request, outElement) {\n var xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = function() {\n if (xmlhttp.readyState == 4) {\n if (xmlhttp.status == 200) {\n outElement.value = xmlhttp.responseText;\n } else {\n outElement.value = \"Error running request. Response: \"\n + xmlhttp.responseText;\n }\n }\n };\n xmlhttp.open('GET', 'https://digitalassetlinks.googleapis.com/v1/' +\n request, true);\n xmlhttp.send();\n }\n\n function executeListRequest() {\n var sourceWebSite = encodeURIComponent(\n document.getElementById('list_source').value);\n var relation = encodeURIComponent(\n document.getElementById('list_relation').value);\n var outputTextArea = document.getElementById('list_response');\n executeRequest('statements:list?source.web.site=' + sourceWebSite\n + '&relation=' + relation, outputTextArea);\n }\n\n function executeCheckRequest() {\n var sourceWebSite = encodeURIComponent(\n document.getElementById('check_source').value);\n var relation = encodeURIComponent(\n document.getElementById('check_relation').value);\n var targetPackageName = encodeURIComponent(\n document.getElementById('check_target_package').value);\n var targetSha256Fingerprint = encodeURIComponent(\n document.getElementById('check_target_sha256_fingerprint').value);\n var outputTextArea = document.getElementById('check_response');\n executeRequest('assetlinks:check?source.web.site=' + sourceWebSite\n + '&relation=' + relation\n + '&target.android_app.package_name=' + targetPackageName\n + '&target.android_app.certificate.sha256_fingerprint='\n + targetSha256Fingerprint\n + '&key=API_KEY',\n outputTextArea);\n }\n\n \u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003ch2\u003eList()\u003c/h2\u003e\n \u003clabel\u003eSource Web Asset:\u003c/label\u003e\n \u003cinput type=\"text\" id=\"list_source\"\n value=\"http://example.digitalassetlinks.org\"\u003e\n \n \u003clabel\u003eRelation:\u003c/label\u003e\n \u003cinput type=\"text\" id=\"list_relation\"\n value=\"delegate_permission/common.handle_all_urls\"\u003e\n \n \u003cbutton type=\"button\" onclick=\"executeListRequest()\"\u003eRun\u003c/button\u003e\u003cbr\u003e\n \u003ctextarea rows=\"20\" cols=\"80\" id=\"list_response\"\u003e\u003c/textarea\u003e\n \u003chr\u003e\n \u003ch2\u003eCheck()\u003c/h2\u003e\n \u003clabel\u003eSource Web Asset:\u003c/label\u003e\n \u003cinput type=\"text\" id=\"check_source\"\n value=\"http://example.digitalassetlinks.org\"\u003e\n \n Relation:\n \u003cinput type=\"text\" id=\"check_relation\"\n value=\"delegate_permission/common.handle_all_urls\"\u003e\u003cbr\u003e\n \n \u003clabel\u003eTarget Android Package:\u003c/label\u003e\n \u003cinput type=\"text\" id=\"check_target_package\"\n value=\"org.digitalassetlinks.sampleapp\"\u003e\n \n \u003clabel\u003eTarget Android Certificate Fingerprint:\u003c/label\u003e\n \u003cinput type=\"text\" id=\"check_target_sha256_fingerprint\"\n value=\"10:39:38:EE:45:37:E5:9E:8E:E7:92:F6:54:50:4F:B8:34:6F:C6:B3:46:D0:BB:C4:41:5F:C3:39:FC:FC:8E:C1\"\u003e\n \n \u003cbutton type=\"button\" onclick=\"executeCheckRequest()\"\u003eRun\u003c/button\u003e\u003cbr\u003e\n \u003ctextarea rows=\"20\" cols=\"80\" id=\"check_response\"\u003e\u003c/textarea\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Go\n\nThere are no Go samples specifically for this version of the Google Digital Asset Links.\n\nHowever, you may be able to adapt one of the other [Go samples](https://github.com/google/google-api-go-client/tree/master/examples).\n\n### Java\n\nThere are no Java samples specifically for this version of the Google Digital Asset Links.\n\nYou may be able to adapt one of the other\n[Java samples](https://developers.google.com/api-client-library/java/apis/).\n\n### .NET\n\nThere are no .NET samples specifically for this version of the\nGoogle Digital Asset Links.\n\nHowever, you may be able to adapt one of the other\n[.NET samples](https://developers.google.com/api-client-library/dotnet/apis/).\n\n### Objective-C\n\nThere are no Objective-C samples specifically for this version of the\nGoogle Digital Asset Links.\n\nHowever, you may be able to adapt one of the other\n[Objective-C samples](https://github.com/google/google-api-objectivec-client-for-rest/tree/master/Examples).\n\n### PHP\n\nThere are no PHP samples specifically for this version of the\nGoogle Digital Asset Links.\n\nHowever, you may be able to adapt one of the other\n[PHP samples](https://github.com/google/google-api-php-client/tree/master/examples).\n\n### Ruby\n\nThere are no Ruby samples specifically for this version of the\nGoogle Digital Asset Links.\n\nHowever, you may be able to adapt one of the other\n[Ruby samples](https://github.com/google/google-api-ruby-client-samples)."]]