【发布时间】:2025-12-06 22:10:01
【问题描述】:
我想在我的 Angular cli 项目中使用 Dropbox API,它是一个 javascript API。 API 附带 Typescript 定义。这是 dist 文件夹的样子。
他们有一个示例函数,它返回写在.ts 文件和.js 文件中的文件列表:
这是basic.js 和basic.ts,它们返回文件列表:
basic.js:
和basic.ts:
这是脚本正在操作的 html 文件以供参考:
<!doctype html>
<html>
<head>
<title>Dropbox TypeScript SDK</title>
<link rel="stylesheet" href="/styles.css">
<script src="/__build__/Dropbox-sdk.min.js"></script>
</head>
<body>
<!-- Example layout boilerplate -->
<header class="page-header">
<div class="container">
<nav>
<a href="/">
<h1>
<img src="https://cfl.dropboxstatic.com/static/images/brand/logotype_white-vflRG5Zd8.svg" class="logo" />
TypeScript SDK Examples
</h1>
</a>
<a href="https://github.com/dropbox/dropbox-sdk-js/tree/master/examples/typescript" class="view-source">View Source</a>
</nav>
<h2 class="code">
<a href="/">examples</a> / basic
</h2>
</div>
</header>
<!-- Example description and UI -->
<section class="container main">
<p>This example fetches the contents of your root Dropbox directory. It uses the <code>Dropbox.filesListFolder()</code> method [<a href="http://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder">docs</a>].</p>
<form onSubmit="return listFiles()">
<input type="text" id="access-token" placeholder="Access token" />
<button type="submit">Submit</button>
</form>
<!-- The files returned from the SDK will be added here -->
<ul id="files"></ul>
<p class="info">To obtain an access token for quick testing, you can go to <a href="https://dropbox.github.io/dropbox-api-v2-explorer/#files_list_folder" target="_blank">API Explorer</a> click the "Get Token" button on the top right, copy the token it creates and then paste it here.</p>
</section>
<!-- Scripts to run example -->
<script src="basic.js"></script>
</body>
</html>
如何使用此 API?我安装了 npm 但如何使用 .d.ts 文件?我应该为我的 Angular 项目使用 .ts 或 .js 代码吗?我想在我的打字稿组件之一中使用 api?我不知道如何在我的角度组件中包含定义和使用这些定义。我假设我在angular-cli.json 中包含Dropbox-sdk.min.js 是我的脚本,但是我在哪里或如何包含.d.ts 文件以及哪些是必要的?我在 Dropbox github 上没有找到相关文档。 github 包含 typescript 和 javascript 使用的完整工作示例,但这是一个令人困惑的项目,因为它似乎将许多不同的东西混合到项目中,我不知道如何为 angular-cli 应用程序翻译它https://github.com/dropbox/dropbox-sdk-js
如果我应该在问题中包含其他内容,请告诉我!
【问题讨论】:
标签: javascript angular typescript dropbox-api