LoginSignup
1
2

More than 3 years have passed since last update.

GmailのAPIでのエラー: Metadata scope doesn't allow format FULL

Posted at

users.messages.getのAPIを使おうとしてのエラーメモです。

https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get

Metadata scope doesn't allow format FULL

というエラーが出ました。

ドキュメントにこれらのパーミッションが必要と書いてあるので許可してたのですが......

https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.metadata
https://www.googleapis.com/auth/gmail.addons.current.message.metadata
https://www.googleapis.com/auth/gmail.addons.current.message.readonly
https://www.googleapis.com/auth/gmail.addons.current.message.action

検証環境

  • Node.js v15.3.0
  • googleapiモジュール v66

試したコード

//省略

gmail.users.messages.get({
    userId: 'me',
    id: `xxxx`,
    // format: 'FULL' 
}, (err, res) => {
   if (err) return console.log('The API returned an error: ' + err);

   console.log(res);
});

//省略

ちなみにallow format FULLとなっていたのは、何も指定しないとデフォルトのフォーマットがFULLになるからという理由です。

  • MINIMAL
  • FULL (デフォ)
  • RAW
  • METADATA

https://developers.google.com/gmail/api/reference/rest/v1/Format

/auth/gmail.metadataのパーミッションを許可しない

Metadata scope doesn't allow format FULL gmailとのことなのでそのままなのですが、APIドキュメントのテスターで試そうとしたら、/auth/gmail.metadataのパーミッションがチェック外れている状態でした。

スクリーンショット 2020-12-16 21.38.10.png

試しにチェックして試すと、テスター上も同様のエラーが発生。

ということでトークンを作成する際に/auth/gmail.metadataを許可しなければOKです。

トークン作成する際のスコープから/auth/gmail.metadataをはずしてトークンを作成しなおしたらいけました。

const SCOPES = [
    `https://mail.google.com/`,
    `https://www.googleapis.com/auth/gmail.modify`,
    `https://www.googleapis.com/auth/gmail.readonly`,
    // `https://www.googleapis.com/auth/gmail.metadata`,
    `https://www.googleapis.com/auth/gmail.addons.current.message.metadata`,
    `https://www.googleapis.com/auth/gmail.addons.current.message.readonly`,
    `https://www.googleapis.com/auth/gmail.addons.current.message.action`
];

まとめ

これはドキュメントミスな気がするけどどうなんでしょう。。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2