全方位
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `Google drive api` `api change requires updates` # Google drive api important security update ## 使用時機 > 因應Google drive api Notice: important security update for Drive document URLs and resource keys. For more information, refer to Access link-shared files using resource keys ## 受影響的系統清單 | System | Sponsor | Status | | ----------------------|----------------|----------| | AI優化觀察名單(Google) | Mike/Robin | | | AI優化觀察名單(Facebook)| Elmo | | | 再行銷名單自動匯入 | Robin | | ## 不懂的地方 1. [http post ](https://developers.google.com/drive/api/v3/manage-uploads#simple) 沒看到有放入credention的地方 maybe answer [try it now](https://developers.google.com/drive/api/v3/reference/files/copy#try-it) ## Mike 整理的solution... ### 甚麼東西會受到影響 如果應用程序使用 Drive API 訪問通過**鏈接共享與用戶共享**的文件,則應用程序可能會受到此更改的影響。 ### 需要做甚麼 為避免訪問Files時出錯,必須更新訪問File的code以包含適當的**resource key**。 > In addition to the item ID, your application may now also need a resource key to access these items. Without a resource key, requests for these items may result in a 404 Not Found error (See below for details). **Note that access to items that are directly shared with the user or group are not affected.** > Items that have a Drive API permission with type=domain or type=anyone, where withLink=true (v2) or allowFileDiscovery=false (v3), will be affected by this security update. 所以我們公司的東西應該不會受到影響 ### 針對甚麼有改變 1. If the file is a shortcut file, then the resource key for the target of the shortcut can be read from the shortcutDetails.targetResourceKey field of the same resource. 2. URL type fields such as exportLinks, webContentLink, and webViewLink will include the resourceKey. 3. Requests to the Drive API can specify one or more resource keys with the **X-Goog-Drive-Resource-Keys HTTP** request header. 4. Changes to Apps Script The DriveApp from Apps Script has been updated to return the resource key of a file or folder with the getResourceKey method. > > Note: When fetching a file or folder, the resource key can be specified on the getFileByIdAndResourceKey or getFolderByIdAndResourceKey methods. ### 要讀的連結 1. [Files](https://developers.google.com/drive/api/v3/reference/files) 2. [Access link-shared files using resource keys ](https://developers.google.com/drive/api/v3/resource-keys) 3. [Class DriveApp](https://developers.google.com/apps-script/reference/drive/drive-app) 4. [integrating with the Drive UI](https://developers.google.com/drive/api/v3/enable-sdk) 5. [permission](https://developers.google.com/drive/api/v3/manage-sharing) > A permission for a file. A permission grants a user, group, domain or the world access to a file or a folder hierarchy ### 我覺得的重點 1. getFolderByIdAndResourceKey(id, resourceKey) > Gets the folder with the given ID and resource key. Resource keys are an additional parameter which need to be passed to access folders that have been **shared using a link**. > > Throws a scripting exception if the folder doesn't exist or the user doesn't have permission to access it. 2. getFolderById(id) > Gets the folder with the given ID. Throws a scripting exception if the folder does not exist or the user does not have permission to access it. ### 似乎只有這些受到影響 [Google to add security resource key to certain Drive files](https://oit.ncsu.edu/2021/07/15/google-to-add-security-resource-key-to-certain-drive-files-and-youtube-video-links/) Drive Files If applied, the security update will impact non-native public Drive files and publicly shared folders in Drive created prior to **2017**. Non-native files are those created outside of Google Workspace (e.g., Microsoft Office files, pdfs) and uploaded to Drive. Users who previously viewed the file will still have access, but other users will not be able to access it via the original link, so file access requests may increase. [沒用到permissions就不需要擔心](https://wordpress.org/support/topic/upcoming-google-security-update/) ## 要做的事情 ### 1. 印出重點drive file 的 field 欄位值 ==> 確認是否有受這次change 影響 1. 先找出重點File的FILEID, 2. 利用FileID找出permissionID, 3. 最後利用FileID加上permissionID來取得PERMISSION 以上可以用GOOGLE的try api來完成 ![](https://i.imgur.com/zhReB7I.png) ![](https://i.imgur.com/RpuENt3.png) ![](https://i.imgur.com/suxjBPc.png) 我們的type是user 並沒有信件中提到的 > Items that have a Drive API permission with type=domain or type=anyone, where withLink=true (v2) or allowFileDiscovery=false (v3), will be affected by this security update. > 另外關於allowFileDiscovery,根據文件只有在type是domain或是anyone時才有 > Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type domain or anyone. ### 2. 如何取得Drive api access token >ANS:已經解決,透過Oauth 2.0 playground >[看這篇筆記](https://hackmd.io/X0Td75_eRnq5hq51dLeWGg) >可以同時取得access token還有refresh token ### 3. 練習用drive web tool send request / postman sendrequest 在這裡取得資源需要兩個東西,一個是API KEY,另外一個是access token,access token有時效性,所以需要透過第二點的Oauth 2.0 playground平台來取得 #### drive web tool drive web tool可以直接send request,不需要設定API KEY那些東西 ![](https://i.imgur.com/FrRlqhd.png) #### postman sendrequest ``` Get request https://www.googleapis.com/drive/v3/files/fileID ``` > fileID是pathvariable的形式,請放入你的檔案的fileID params ``` field:kind%2Cowners%2Cname key:APIKEY(可在GCP上獲得) ``` > field決定你想要得到哪些資訊欄位,可以參考[Google官方文件的File Resource representations](https://developers.google.com/drive/api/v3/reference/files)並且我們使用**%2C**來隔開 Headers ``` Authorization:Bearer ya29.a0ARrdaM-ppsPDe946r02_AKZ07d3aYbMJ9vJhWJo7mMIq2EC_5iXDBbhAGnxMEuDxpevKQyH7N0PE1kfexb6eWKuZM07Sb5WpS-V0YntSd-hKR6765TD19UwKgVYM6rUWmhLEOkmuJE5w-KH_jwVJC_l9vrMq Accept:application/json ``` > Bearer後面空一個空白然後加上access token ![](https://i.imgur.com/DaEjGgK.png) ![](https://i.imgur.com/reWKYyz.png) ### 4. 如何取得resource key ### Oauth2.0 doc [oauth2](https://translate.google.com/translate?hl=zh-TW&sl=en&tl=zh-TW&u=https%3A%2F%2Fdevelopers.google.com%2Fidentity%2Fprotocols%2Foauth2&anno=2&prev=search)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully