4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ElixirでBigQueryにPOSTしたい

Posted at

google_api_big_queryを使ってBigQueryにDatasetやテーブルを作りたかった。
しかし、テーブルは取得できるのに何故かPOSTの処理はできないのでハマってしまったので解決方法を残す。
(Insufficient Permissionと出ていた)

対象読者

  • 未来の僕
  • ElixirでBigQueryにデータを突っ込みたいと思っている人で Insufficient Permissionって言われて困ってる人

結論

gothでトークンを取得するときに以下のようにしていた。

# これだとPOST系の処理は失敗する
{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform.read-only")
GoogleApi.BigQuery.V2.Connection.new(token.token)
# これが正解
{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform")
GoogleApi.BigQuery.V2.Connection.new(token.token)

Goth.Token.for_scope("URL")に指定したURLに read-onlyが指定されていた...
過去に一度BQからレコードを取得する処理を書いたときのコードを何も考えずにコピペしたためGET系の操作はできたがPOST系の処理ができないことに気が付かなかった...

 感想

気がついてしまえばなんてことは無いんだけどここに至るまでにいろいろなことを試しました。
(サービスアカウントを一時的にProjectOwnerに指定してみたりとかソースコードを追いかけたり。)
結果的にはBigQueryのAPI周りに詳しくなったので良かったのですが何も考えずにコピペするのはだめですねぇ。。。(´;ω;`)

4
0
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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?