json-api-response-converter 相关问题


Laravel POST 方法返回状态:405 不允许在 POST 方法上使用方法

请查找以下信息: NoteController.php 请查找以下信息: NoteController.php <?php namespace App\Http\Controllers; use App\Http\Requests\NoteRequest; use App\Models\Note; use Illuminate\Http\JsonResponse; class NoteController extends Controller { public function index():JsonResponse { $notes = Note::all(); return response()->json($notes, 200); } public function store(NoteRequest $request):JsonResponse { $note = Note::create( $request->all() ); return response()->json([ 'success' => true, 'data' => $note ], 201); } public function show($id):JsonResponse { $note = Note::find($id); return response()->json($note, 200); } public function update(NoteRequest $request, $id):JsonResponse { $note = Note::find($id); $note->update($request->all()); return response()->json([ 'success' => true, 'data' => $note, ], 200); } public function destroy($id):JsonResponse { Note::find($id)->delete(); return response()->json([ 'success' => true ], 200); } } NoteRequest.php <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class NoteRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ 'title', 'required|max:255|min:3', 'content', 'nullable|max:255|min:10', ]; } } Note.php(模型) <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Note extends Model { use HasFactory; protected $guarded = []; } api.php <?php use App\Http\Controllers\NoteController; use Illuminate\Support\Facades\Route; Route::prefix('v1')->group(function () { Route::resource('/note', NoteController::class); }); php artisan 路线:列表 GET|HEAD / ...................................................................................................................... POST _ignition/execute-solution ............... ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController GET|HEAD _ignition/health-check ........................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController POST _ignition/update-config ........................ ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController GET|HEAD api/v1/note .......................................................................... note.index › NoteController@index POST api/v1/note .......................................................................... note.store › NoteController@store GET|HEAD api/v1/note/create ................................................................. note.create › NoteController@create GET|HEAD api/v1/note/{note} ..................................................................... note.show › NoteController@show PUT|PATCH api/v1/note/{note} ................................................................. note.update › NoteController@update DELETE api/v1/note/{note} ............................................................... note.destroy › NoteController@destroy GET|HEAD api/v1/note/{note}/edit ................................................................ note.edit › NoteController@edit GET|HEAD sanctum/csrf-cookie .................................. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show 迅雷请求(同邮递员) JSON 请求 { "title": "Hello World", "content": "Lorem ipsum." } 尝试发出 JSON POST 请求并获取状态:405 方法不允许并且我正在使用 php artisan 服务,如果需要,我可以提供 GIT 项目。请告诉我。 您的验证规则看起来不正确。在您的 NoteRequest 类中,规则应该是一个关联数组,其中键是字段名称,值是验证规则。但是,在您的代码中,规则被定义为以逗号分隔的字符串列表。这可能会导致验证失败并返回 405 Method Not allowed 错误。 public function rules() { return [ 'title' => 'required|max:255|min:3', 'content' => 'nullable|max:255|min:10', ]; }


在这个curl api中将不记名授权令牌放在哪里

我正在使用 imageqrcode (https://imageqrcode.com/apidocumentation) 的新 api 功能来动态生成图像 QR 码,使用 php: 我正在使用 imageqrcode (https://imageqrcode.com/apidocumentation) 的新 api 功能来动态生成图像 QR 码,使用 php: <?php $api_key = 'xxxxxxxxxx'; //secret // instantiate data values $data = array( 'apikey' => $api_key, 'qrtype' => 'v1', 'color' => '000000', 'text' => 'https://wikipedia.com', ); // connect to api $url = 'https://app.imageqrcode.com/api/create/url'; $ch = curl_init($url); // Attach image file $imageFilePath = 'test1.jpg'; $imageFile = new CURLFile($imageFilePath, 'image/jpeg', 'file'); $data['file'] = $imageFile; curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // Handle the response $result = json_decode($response, true); if ($result && isset($result['downloadURL'])) { // Successful request $download_url = $result['downloadURL']; echo "Download URL: $download_url"; } else { // Handle errors echo "Error: " . print_r($result, true); } ?> 在文档中显示有变量“serialkey”: 图片二维码API文档 API文档 生效日期:2023年11月15日 图像二维码 API 是一项接受 HTTPS 请求以生成图像或 gif 二维码的服务,主要由开发人员使用。 图像二维码 - URL JSON 请求(POST):https://app.imageqrcode.com/api/create/url apikey //你的apikey 序列号//你的序列号 qrtype //字符串,最少 2 个字符,最多 2 个字符v1 或 v2,v1 适用于 QR 类型 1,v2 适用于类型 2 color //数字,最小 6 位,最大 6 位,例如000000 为黑色 text //url,最少 15 个字符,最多 80 个字符https://yourwebsite.com file //图像文件 (jpg/jpeg/png),最大 1 MB 文件大小 现在没有信息将该序列密钥作为标准承载授权令牌放在哪里???如果没有此信息,我无法连接到 api 我尝试在没有不记名令牌的情况下连接它,因为我认为它可以匿名连接到 api,但也不起作用,我现在很困惑,因为我仍在学习 PHP 和 Laravel 看起来 serialkey 不是不记名令牌,而是一个应该与其他参数(如 apikey、qrtype、color、text 和 )一起包含在 POST 数据中的参数file。您可以在 PHP 代码的 serialkey 数组中包含 $data。 $data = array( 'apikey' => $api_key, 'serialkey' => 'your_serial_key', // Add this line 'qrtype' => 'v1', 'color' => '000000', 'text' => 'https://wikipedia.com', );


.Net core Web API 将 json/model 值设置为 NULL

我有一个 .Net core Web API,它接受以下 JSON:(RequestModel) { “isSpecimen”:正确, “形式”: { “网络”:{ “abc1...


使用 Foursquare 的 API 将场地放入 NSArray

我正在尝试将场地保存到 NSArray 中。 Venue 是 NSDictionary Response 中的一个数组。我想要一个包含所有场地的 NSArray,这样我就可以填充一个表。 NSURL *url = [[NSURL alloc] initWith...


Retrofit API 出现 MalformedJsonException?

我需要发送一个json到我的网络服务,json是: { “萨拉”:{ "usuario": "%@", "对手": "%@", "atualizacao": "%@", “设备”: ”%@”, "device_tipo": "ios...


如何使用map函数将JSON数据输入到div元素中

我有一个API URL,是这样的 https://api-amvstrm.nyt92.eu.org/api/v1 /popular 和 API 响应如下所示 t itle": "地牢网格", "id": "地牢-...


是什么原因导致 JsonException: JSON 值无法转换?

C# 10 / .NET 6 / System.Text.Json 我正在使用一个以 JSON 响应形式返回的 API。我正在尝试使用 System.Text.Json 将 JSON 响应反序列化为类。我收到了 JsonExce...


Google 地图 API 通过 API 发出的路线请求返回 ZERO_RESULTS,但适用于 Google 地图

有问题的呼叫是: https://maps.googleapis.com/maps/api/directions/json?origin=35.73455050,-95.31531510&destination=29.67404860,-95.54087240&waypoints=29.92853940,-95.29782860...


Golang - 返回的 JSON 顶级字段是可变的。如何在结构体中使用

我有一个来自 API 的 JSON 响应,如下所示: { “1091500”:{ “数据”: { “价格概述”:{ "final_formatted": "5 美元...


如何在 C# 中获取没有任何空格的 JSON 格式的 WebResponse?

我尝试使用 WebRequest 调用 C# 中的 API 端点,并使用 WebResponse 来获取响应。我正在接收 JSON,但 JSON 响应充满了很多空格,我想去掉它们......


JSON API 错误-无法读取数据,因为它丢失。- 在 iOS 中,swift

我有 JSON 数据字符串结构,例如, 数据: { “项目”: [ { “种类”:“自定义搜索#结果”, "title": "XHAOYEAHX 40,60,110,150pcs鞋C...


如何使用Discord API更改DM群组图标?

我无法使用 Discord API 更改 DM 群组图标。 我发送了补丁请求: 导入请求 requests.patch(url=f'https://discord.com/api/v9/channels/{group_id}', json={'icon': f'data:image/png;


React 中 fetch 调用后的清理函数

const[imageContainer,setImageContainer] = useState([]) 常量导航 = useNavigate(); 使用效果(()=>{ Promise.all([ fetch("https://www.themealdb.com/api/json/v1/1/


无法使用.Net 8 Api 将 JSON 值转换为 System.DateOnly

使用.Net 8,我尝试将各种格式的日期传递到我的 Api 端点,但无法克服此错误。我收到 400 响应,并显示错误:JSON 值无法转换为系统。


解析Java中一行中存在的多个JSON对象

我目前正在使用 OMDB API,它可以将 get 查询作为 JSON 对象或 XML 返回。使用 JSON 是我想学习的东西,对于我来说,它通常看起来是最好的解决方案


C# 解析具有多个结果的 JSON 字符串

我正在尝试解析具有多个结果的 JSON 字符串。我正在从我们的服务台票务系统调用 API。我能够从 API 中获取我想要的所有票务信息到 v...


为什么我有很多对 API 的请求,需要在 next.js 13v 的服务器端获取数据

我使用 Next.js 13v 在服务器端获取数据。 我的组件 const 页脚 = async () => { // 获取数据 const allCategories = (await getAllCategories({})).data; 返回 我使用 Next.js 13v 在服务器端获取数据。 我的组件 const Footer = async () => { // Get data const allCategories = (await getAllCategories({})).data; return <footer className={styles.footer}></footer>; }; 我的功能 export const getAllCategories = async ( params: IGetAllCategoriesRequest, ): Promise<AxiosResponse<IGetAllCategoriesResponse>> => { const url = 'static-pages/category/public'; const response = await axiosInstance.get<IGetAllCategoriesResponse>( url, { params: params, }, ); return response; }; 如果请求成功,我有一个请求 但是如果出现错误,我有很多请求,然后重定向到错误页面 本机获取具有相同的行为 那么为什么我在 next.js 13v 中对 API 有很多请求并在服务器端获取数据? 可能和开发模式有关。我发现这篇文章可能与此行为有关:https://dev.to/noclat/fixing-too-many-connections-errors-with-database-clients-stacking-in-dev-mode-with-next -js-3kpm


无法使用 ASP.NET Core 8 Web API 将 JSON 值转换为 System.DateOnly

使用 .NET 8,我尝试将各种格式的日期传递到我的 API 端点,但无法克服此错误。我收到 400 响应,其中包含以下错误: JSON 值无法转换为系统值。


具有动态键的对象无法在电源自动化中生成解析 JSON 模式

我正在 Power Automate 中进行一个 API 调用,我收到以下 JSON 的响应 { “分页”:{ “开始”:0, “计数”:10, “链接”:[], ...


使用 Swift 调用 Flickr API

我试图从 Flickr API 获取一些 JSON 数据,但我的 Swift 代码无法正常工作。 这是基于 Jameson Quave 关于使用 Swift 发出 API 请求的教程 func GetFlickrData(标签:字符串...


React Native Axios 正在发送整个对象,而不仅仅是值

这让我发疯。我只是尝试将日期发布到我的 api,但收到“JSON 值无法转换为 System.DateTime”的 json 错误。 原因是axios或者


无法通过PAT令牌调用Azure DevOps Rest Api

我正在尝试使用 Azure DevOps Rest api 将保存在本地目录(桌面)中的 json 文件导入到 Azure DevOps 库变量组。 这是剧本。 $jsonbody = Get-Content -Path "C: ar...


如何使用 YouTube API 版本 3 获取视频时长?

我正在使用 YouTube API v3 来搜索 YouTube。 https://developers.google.com/youtube/v3/docs/search 如您所见,响应 JSON 不包含视频时长。有没有办法获得视频硬膜...


SpringBoot中json转换的正确方式和位置

我正在开发一个小型 SpringBoot 项目。将订单数据存储在 postgres 数据库中。我有一个为我的前端返回 json 的 API。 我在问自己到底应该在哪个地方转换我的...


JS Fetch 在给定“application/json”标头时返回 HTML

我有一个 API 的获取请求代码,我知道它会返回 JSON(请参阅下面的节点 - https 请求。)但是,即使我设置了“应用程序...”的标头,响应也会以 text/html 形式返回。


尝试访问 vuetify 中 v-select (itemProps) 的嵌套 json 值

我正在尝试在 vuetify 中制作一个 v-select 组件,它从 API 获取数据并将其显示为选项,但奇怪的是收到的 json 数据在对象内部有一个对象,但它不能...


通过 Walmart API 批量购买商品

我尝试通过 Walmart API 批量购买商品,但收到错误:设置此产品时发生意外错误。请尝试再次摄取该物品。 我使用 PHP,这是我的 json: { ...


在iPhone上提取JSON响应的特定部分

我正在考虑在我的应用程序中添加一个距离计算器。我一直在查看 Google 的 API,我似乎无法解码 JSON。我已经用 PHP 成功做到了这一点。其代码是: 潜艇...


WireMock 在小数值末尾去掉零

我可能需要模拟一个返回 JSON 的 API,其中包含尾数为 0 的十进制格式的值等。没有引号,所以类似 {"some":"stuff...


如何在不重新加载页面的情况下发送带有文件的表单?

我尝试在ajax中发送表单而不重新加载页面,但我看到,文件上的链接不存在...... 我有下一个表格: 我尝试在ajax中发送表单而不重新加载页面,但我看到,文件上的链接不存在... 我有下一个表格: <form id="settings" method="POST" enctype="multipart/form-data"> ... <input type="file" id="logo" style="display:none;" name="logo" accept="image/png, image/jpeg, image/gif"> <button type="submit" id="send" class="btn btn-primary">save</button> </form> Ajax 脚本: $('#settings').submit(function(e){ e.preventDefault(); var form = $(this).serialize(); alert(form); // file is not attached... $.ajax({ url : '/settings', type : 'POST', crossDomain : false, data : form, contentType : 'multipart/form-data', dataType : 'json', progressData: false, cache : false, success : function(r){ alert (111); } }).fail(function(){ console.log('Error occured!'); }); }); 在服务器端,我收到错误: org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为未找到多部分边界 我尝试不序列化表单,而是写了 data : form -> data : new FormData(this) 此选项会导致错误“非法调用”。如何在不重新加载页面的情况下发送带有文件的表单? 要使用 AJAX 发送带有文件的表单而不重新加载页面,您需要使用 FormData 来正确处理文件上传。 <form id="settings" method="POST" enctype="multipart/form-data"> <!-- Other form fields --> <input type="file" id="logo" name="logo" accept="image/png, image/jpeg, image/gif"> <button type="submit" id="send" class="btn btn-primary">Save</button> </form> $(document).ready(function() { $('#settings').submit(function(e){ e.preventDefault(); var formData = new FormData(this); $.ajax({ url: '/settings', type: 'POST', data: formData, contentType: false, processData: false, cache: false, success: function(response){ alert('Form submitted successfully!'); // Handle the response from the server }, error: function(){ console.log('Error occurred!'); } }); }); });


Redux 工具包解析非 JSON 响应时出错

我正在尝试 redux 工具包,目前有以下切片和突变: 导出 const apiSlice = createApi({ 减速器路径:“api”, 基本查询: fetchBaseQuery({ 基本网址:“


Symfony 中的日期时间反序列化

我正在尝试在 API 端点中反序列化 JSON 对象,但遇到了一些问题。 我正在使用 #[MapRequestPayload] 属性和默认 SerializerInterface 实现。跑步


我需要在API网关中进行哪些设置才能接受压缩的有效负载

我有一个客户端应用程序,它将压缩数据发送到aws api网关。数据是默认压缩的。请求头如下: 内容编码:deflate 内容类型:application/json ...


错误:ENOENT:Next.js 中没有这样的文件或目录

我正在尝试从 Next.js 中的 API 路由更改 JSON 文件中的数据。 从“fs/promises”导入 fs; 从“路径”导入路径; 导出异步函数 ReplaceData(index, data) { ...


如何保护来自 iPhone 的 JSON 请求?

我有一个带有 JSONP API 的 Web 应用程序,我正在与我的 iPhone 应用程序一起使用。如何确保这一点,以便来自其他地方的请求将无法访问我的 API? 澄清:我的数据并不那么重要。你会...


当从 ASP.NET Core MVC 获取 api 到 Reactjs 时,是什么提示 get 方法返回 HTML 而不是它应该返回的 json 数据?

我正在尝试创建一个应用程序,其中客户端前端使用react.js 制作,后端使用ASP.Net Core MVC。我正在尝试从 api 获取数据以渲染


使用带有改造 API 的 GSON 解析 JSON 时出错

这是我正在使用的 POJO 或模型类,我能够从服务器获取响应,但它抛出 SyntaxException 和 MalformedJSONException //模型类: 公共类应用程序用户{ 公开


通过惰性 API 进行 Android 改造 - 响应最近一小时的数据

我正在使用惰性 API 进行改造。 json数据收到了,一切正常。唯一的问题是下一次检索是从缓存中...... 仅1小时后就得到新数据。 我该如何解决这个问题。 val okHttpCl...


Laravel9 response()->stream() 使用 fwrite() 得到空结果

我需要将大量数据导出为 CSV 字符串。 所以我尝试将 fopen('php://stdout', w) 与 fwrite($file, $data) 一起使用。 但 Laravel response()->stream() 不会返回任何内容,也不会出现错误。 我...


当我尝试在 React 中使用 put 方法时,出现错误 400:“该字段是必需的”

我看不出代码中有什么问题;我想使用 Put 方法,但是当我这样做时,API 返回的响应是: “错误”:{ “$”:[ “JSON 值 c...


使用jwt身份验证在grafana中导入JSON数据

我计划创建一个 grafana 仪表板来监控我的网络应用程序性能。 我使用我的自托管 umami 实例收集网站登陆页面的分析。 Umami 提供 REST api 供阅读


我无法用vue.js显示json

我需要使用 v-for 显示 json 中的产品数组,但我无法这样做。 我正在尝试显示产品数组中的 json 数据,但它不起作用。 Vue.js 我需要使用 v-for 显示 json 中的产品数组,但我无法这样做。 我正在尝试显示产品数组中的 json 数据,但它不起作用。 Vue.js <div class="box" v-for="product in products" :key="product.id"> <h2>Produto {{ product.name }}</h2> <h3>Situação {{ product.situation }}</h3> </div> export default { data() { return { products: [], }; }, methods: { async getData() { try { const req = await fetch("http://localhost:3000/products"); const data = await req.json(); this.products = data.products; console.log("data" + data); } catch (error) { console.error("Error fetching data:", error); } }, mounted() { this.getData(); }, }, }; JSON: { "products": [ { "id": "a898", "name": "Claudio Romano", "situation": "Ativo" } ] } 您问错了问题,因为该问题与 JSON 无关。如果您对此进行调试,您会注意到 console.logs 不执行,这意味着问题更为根本,因为该方法本身并未实际运行。 根本问题是mounted()不应该在methods内部。您正在使用 Vue 的选项 API,其中 data()、methods 和 mounted 都是独立的、单独的“选项”。您需要将安装移动到方法之外,它应该是一个“兄弟”选项。 export default { data() { ... }, methods: { ... }, mounted() { this.getData(); }, }; 游乐场演示


有没有办法绕过 Excel 查询中的基本身份验证?

我有一个excel文件,我使用API从网络获取数据。我的数据以 json 格式返回。 我将查询安排在“查询”和“属性”中,以便数据经常更新。 我需要能够分享我的f...


Json使用内部 JsonString 解码 json

我有下一个要解码的 Json 字符串 [{ “材料 ID”:1193, “材料代码”:“AN00000211”, “material_name”:“玛格丽塔披萨”...


角度项目中的json服务器

在我的角度项目中,我希望使用json-server。安装json服务器后,使用此代码“json-server --watch db.json”创建db.json文件。然后给出此错误。 文件:///C:/用户/...


来自有序字典的Python Json

我正在尝试创建一个嵌套的 Json 结构,如下所示: 示例 Json: { “id”:“德”, “密钥”:“1234567”, “来自”:“[email protected]”, “过期”:“2018-04-2...


如何在SQL中更新Json字符串

我有这个 JSON 字符串: [ { "名称": "TG名称", “价值”: ”” }, { “姓名”:“ISD”, “值”:“{\”WC\...


无法从数组中找到json路径

我是 JSON 新手。我有一个 LossHistory Json,我需要从中过滤出等于“General Liab - Excess”的“LineOfBusinessCode”,我需要显示特定的“Lossyear&qu...


Apache Superset 在 MySQL JSON 字段方面遇到问题

我有一个 MySQL 数据库,其中的记录包含 JSON 类型字段。 JSON 类型字段的示例是 {.... “callAttributes”:{“teamId”:“红色”,“operatorId”:&...


通过更少的 Java API 调用来映射 Google 云端硬盘内容的有效方法

大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我做这样的事情: 哈希映射 大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我正在做这样的事情: HashMap<String, Strin> foldersPathToID = new HashMap<>(); //searching all folders first saving their IDs searchAllFoldersRecursive(folderName.trim(), driveId, foldersPathToID); //then listing files in all folders HashMap<String, List<File>> pathFile = new HashMap<>(); for (Entry<String, String> pathFolder : foldersPathToID.entrySet()) { List<File> result = search(Type.FILE, pathFolder.getValue()); if (result.size() > 0) { String targetPathFolder = pathFolder.getKey().trim(); pathFile.putIfAbsent(targetPathFolder, new ArrayList<>()); for (File file : result) { pathFile.get(targetPathFolder).add(file); } } } 递归方法在哪里: private static void searchAllFoldersRecursive(String nameFold, String id, HashMap<String, String> map) throws IOException, RefreshTokenException { map.putIfAbsent(nameFold, id); List<File> result; result = search(Type.FOLDER, id); // dig deeper if (result.size() > 0) { for (File folder : result) { searchAllFoldersRecursive(nameFold + java.io.File.separator + normalizeName(folder.getName()), folder.getId(), map); } } } 搜索功能是: private static List<com.google.api.services.drive.model.File> search(Type type, String folderId) throws IOException, RefreshTokenException { String nextPageToken = "go"; List<File> driveFolders = new ArrayList<>(); com.google.api.services.drive.Drive.Files.List request = service.files() .list() .setQ("'" + folderId + "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false") .setPageSize(100).setFields("nextPageToken, files(id, name)"); while (nextPageToken != null && nextPageToken.length() > 0) { try { FileList result = request.execute(); driveFolders.addAll(result.getFiles()); nextPageToken = result.getNextPageToken(); request.setPageToken(nextPageToken); return driveFolders; } catch (TokenResponseException tokenError) { if (tokenError.getDetails().getError().equalsIgnoreCase("invalid_grant")) { log.err("Token no more valid removing it Please retry"); java.io.File cred = new java.io.File("./tokens/StoredCredential"); if (cred.exists()) { cred.delete(); } throw new RefreshTokenException("Creds invalid will retry re allow for the token"); } log.err("Error while geting response with token for folder id : " + folderId, tokenError); nextPageToken = null; } catch (Exception e) { log.err("Error while reading folder id : " + folderId, e); nextPageToken = null; } } return new ArrayList<>(); } 我确信有一种方法可以通过很少的 api 调用(甚至可能是一个调用?)对每个文件(使用文件夹树路径)进行正确的映射,因为在我的版本中,我花了很多时间进行调用 service.files().list().setQ("'" + folderId+ "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false").setPageSize(100).setFields("nextPageToken, files(id, name)"); 每个子文件夹至少一次......并且递归搜索所有内容需要很长时间。最后,映射比下载本身花费的时间更多...... 我搜索了文档,也在此处搜索,但没有找到任何内容来列出具有一个库的所有驱动器调用任何想法? 我想使用专用的 java API 来获取共享 GoogleDrive 中的所有文件及其相对路径,但调用次数尽可能少。 提前感谢您的时间和答复 我建议您使用高效的数据结构和逻辑来构建文件夹树并将文件映射到其路径,如下所示 private static void mapDriveContent(String driveId) throws IOException { // HashMap to store folder ID to path mapping HashMap<String, String> idToPath = new HashMap<>(); // HashMap to store files based on their paths HashMap<String, List<File>> pathToFile = new HashMap<>(); // Fetch all files and folders in the drive List<File> allFiles = fetchAllFiles(driveId); // Build folder path mapping and organize files for (File file : allFiles) { String parentId = (file.getParents() != null && !file.getParents().isEmpty()) ? file.getParents().get(0) : null; String path = buildPath(file, parentId, idToPath); if (file.getMimeType().equals("application/vnd.google-apps.folder")) { idToPath.put(file.getId(), path); } else { pathToFile.computeIfAbsent(path, k -> new ArrayList<>()).add(file); } } // Now, pathToFile contains the mapping of paths to files // Your logic to handle these files goes here } private static List<File> fetchAllFiles(String driveId) throws IOException { // Implement fetching all files and folders here // Make sure to handle pagination if necessary // ... } private static String buildPath(File file, String parentId, HashMap<String, String> idToPath) { // Build the file path based on its parent ID and the idToPath mapping // ... }


© www.soinside.com 2019 - 2024. All rights reserved.