8
n8n 中文网amn8n.com

AIAutomationPro 从 Google Drive 恢复凭据

中级

这是一个DevOps领域的自动化工作流,包含 14 个节点。主要使用 If, N8n, Code, Wait, SplitOut 等节点。 从Google Drive备份恢复n8n凭据,具备重复保护功能

前置要求
  • Google Drive API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "MpylFkqFRYso6hYt",
  "meta": {
    "instanceId": "b3df22d2875c82e3ba1883c50049ed9cee0bcabf99d2b486961d2245a09e3964",
    "templateCredsSetupCompleted": true
  },
  "name": "AIAutomationPro 从 Google Drive 恢复凭据",
  "tags": [],
  "nodes": [
    {
      "id": "60aa7e22-1d8a-4d93-864a-3f0f4f01418a",
      "name": "将文件转换为 JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        920,
        -40
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson",
        "destinationKey": "=data",
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "6ea6ffa1-ee03-4cb5-ba7a-55c30b5774f1",
      "name": "检查跳过的凭据",
      "type": "n8n-nodes-base.if",
      "position": [
        1740,
        -20
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "ad031296-4ac0-4087-bc35-7975a2cc25e6",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $('Loop Over Items').item.json.name }}",
              "rightValue": ""
            },
            {
              "id": "ca912a57-6a4b-4b9a-be0e-37b69d3e4917",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              },
              "leftValue": "={{ $('Aggregate Cridentials').first().json.name }}",
              "rightValue": "={{ $('Loop Over Items').item.json.name }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "460c8e94-5375-4d26-ac22-12b3fe1bbbd1",
      "name": "恢复 N8N 凭据",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1960,
        0
      ],
      "parameters": {
        "data": "={{ JSON.stringify($('Loop Over Items').item.json.data) }}",
        "name": "={{ $('Loop Over Items').item.json.name }}",
        "resource": "credential",
        "requestOptions": {},
        "credentialTypeName": "={{ $('Loop Over Items').item.json.type }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "S63rln42rAvGFfBB",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "70c258f9-91eb-4fae-af40-077e50522452",
      "name": "Google Drive 下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        720,
        -40
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Google Drive Get Credentials File').first().json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "q8OibtSjVurZl2tb",
          "name": "AI Auto Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "089faa43-cb45-4daa-baea-770bd82d79fc",
      "name": "Google Drive 获取凭据文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        520,
        -40
      ],
      "parameters": {
        "limit": 1,
        "filter": {},
        "options": {},
        "resource": "fileFolder",
        "queryString": "n8n_backup_credentials.json"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "q8OibtSjVurZl2tb",
          "name": "AI Auto Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "254aa95c-cde9-463e-9baa-d2662787a848",
      "name": "执行命令获取所有凭据",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        -100,
        -40
      ],
      "parameters": {
        "command": "npx n8n export:credentials --all --decrypted"
      },
      "typeVersion": 1
    },
    {
      "id": "59d99f04-3b55-4b7a-b237-c2125933589f",
      "name": "JSON 格式化数据",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        -40
      ],
      "parameters": {
        "jsCode": "// Function to beautify JSON\nfunction beautifyJson(jsonString) {\n  try {\n    // Parse the JSON string\n    const jsonObject = JSON.parse(jsonString);\n\n    // Format the JSON with indentation\n    return jsonObject; // Return the parsed object directly\n  } catch (error) {\n    // Return the error message if JSON is invalid\n    return `Invalid JSON: ${error.message}`;\n  }\n}\n\n// Retrieve the JSON object from the input data\nconst input = $input.all()[0].json;\n\n// Extract the JSON string from the stdout field\nconst jsonString = input.stdout.match(/\\[{.*}\\]/s);\n\n// Check if a valid JSON string is found\nif (!jsonString) {\n  return {\n    json: {\n      error: \"No valid JSON string found in stdout.\"\n    }\n  };\n}\n\n// Beautify the JSON\nconst beautifiedJson = beautifyJson(jsonString[0]);\n\n// Output the beautified JSON, ensuring each entry is in an object with a 'json' key\nconst output = beautifiedJson.map(entry => ({ json: entry }));\n\n// Return the output\nreturn output;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1a2a5b3f-6440-41d0-b840-ef19540fd2ae",
      "name": "聚合凭据",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        300,
        -40
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "name"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8d62c789-3bf2-48a7-8ac8-9df721b133d0",
      "name": "拆分输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1120,
        -40
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "f4f6b751-78f9-48b7-9a5d-85466f134556",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1520,
        -40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ab6eddef-6aaf-4ef8-a3a9-a2a2e3092565",
      "name": "拆分输出1",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1320,
        -40
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "edd4e9fd-36d9-4572-add7-5fd0d29f4ec8",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -120
      ],
      "parameters": {
        "width": 2591,
        "height": 372,
        "content": "## 导入凭据到 N8N"
      },
      "typeVersion": 1
    },
    {
      "id": "cb46ba37-1171-488e-a8fc-943e90d5103e",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        2180,
        0
      ],
      "webhookId": "364168eb-6800-4a29-8fe8-8cd9f9e5b4bb",
      "parameters": {
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "82a3b7e8-7079-4ef5-bc5c-d9fce0f1c1d7",
      "name": "点击触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -520,
        -40
      ],
      "parameters": {},
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "23e5b115-e204-4db0-905e-7d5254b2729a",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Check For Skipped Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On Click Trigger": {
      "main": [
        [
          {
            "node": "Execute Command Get All Cridentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JSON Formatting Data": {
      "main": [
        [
          {
            "node": "Aggregate Cridentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Cridentials": {
      "main": [
        [
          {
            "node": "Google Drive Get Credentials File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Files To JSON": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Restore N8n Credentials": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Download File": {
      "main": [
        [
          {
            "node": "Convert Files To JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check For Skipped Credentials": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Restore N8n Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Get Credentials File": {
      "main": [
        [
          {
            "node": "Google Drive Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command Get All Cridentials": {
      "main": [
        [
          {
            "node": "JSON Formatting Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 开发运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量14
分类1
节点类型12
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Daniel Ng

Daniel Ng

@danielng

A Growth Hacker, Digital Marketer & AI Automation Builder with 10+ years of experience in Digital Marketing & Workflow Automation. Based in Helsinki, Finland. For questions about my templates and customization, contact me at: daniel@aiautomationpro.org

外部链接
在 n8n.io 查看

分享此工作流