0
3

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 5 years have passed since last update.

Python で Domo の アクセストークンを取得する

Last updated at Posted at 2017-09-21

Domo の user と password から access_token を取得する方法です。

main_get_token.py
# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	main_get_token.py
#
#					Sep/21/2017
#
# ------------------------------------------------------------------
import	sys
import	requests
#
from domo_config import domo_config_proc
from get_access_token import get_access_token_proc
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
config = domo_config_proc()
access_token = get_access_token_proc(config)
#
print(access_token)
#
sys.stderr.write("*** 終了 ***\n")
#
# ------------------------------------------------------------------

次の user と password は書き換えて下さい。

domo_config.py
# -*- coding: utf-8 -*-
#
#	common/domo_config.py
#
#					Sep/21/2017
#
# ------------------------------------------------------------------
import	sys
#
#
# ------------------------------------------------------------------
def domo_config_proc():
#
	config = {}
#
	config['user']="0ab7adx9-1ep8-44bb-a622-67g91f578e94"
	config['password']="cd295ed5dd33eb70914f8fx61523e8370b9e72d23c084a1209154ad6d203b1fx"
#
#
	return config
#
# ------------------------------------------------------------------
get_access_token.py
# -*- coding: utf-8 -*-
#
#	common/get_access_token.py
#
#					Sep/21/2017
#
# ------------------------------------------------------------------
import	sys
import	requests
import	json
#
#
# ------------------------------------------------------------------
def get_access_token_proc(config):
#
	url="https://api.domo.com/oauth/token"

	params= {
		"grant_type": "client_credentials",
		'scope': 'data'
		}

	rr = requests.get(url,params=params,auth=(config['user'],config['password']))
	print(rr.status_code)
	json_str = rr.text
	dict_aa = json.loads(json_str)
	access_token = dict_aa['access_token']
#
	return access_token
#
# ------------------------------------------------------------------

API の仕様はこちら
Obtaining an access token

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?