Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Beispielcode ist oft die einfachste Möglichkeit, den Umgang mit einer API zu erlernen. Für Links
zu Google Digital Asset Links-Beispielen gezeigt haben, wählen Sie unten eine Programmiersprache aus.
Wenn die Beispielseite einer Bibliothek noch kein Beispiel für die Google Digital Asset Links enthält, können Sie diese Bibliothek trotzdem verwenden. Möglicherweise können Sie auch Beispiele anpassen, die für eine andere Google API bereitgestellt werden.
Python
Hier ist ein einfaches Python-Beispiel, in dem alle Aussagen einer bestimmten Website aufgelistet und dann geprüft wird, ob diese Website die delegate_permission/common.handle_all_urls-Erklärung zu einer bestimmten Android-App enthält.
Hier ist ein einfaches JavaScript-Beispiel, mit dem Sie alle Aussagen einer bestimmten Website auflisten können.
und prüfen, ob eine bestimmte Aussage auf dieser Website vorhanden ist.
[null,null,["Zuletzt aktualisiert: 2025-08-31 (UTC)."],[[["\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)."]]