

Python-FitbitというFitbit
APIをPythonから利用するモジュールを用い、Heroku上のプログラムからOAuth2認証をして、アクセストークン・リフレッシュトークンを取得したい。

Python-Fitbit  
<https://github.com/orcasgit/python-fitbit>

手順はこのサイトを参考にしました。  
<http://blog.mr-but-dr.xyz/programming/fitbit-python-heartrate-howto/>

dev.fitbit.comでhttp://127.0.0.1:8080をコールバックURLに指定し、ローカルでプログラムを実行すると、ブラウザが開いて認証に成功し、次の処理に進むのですが、<https://appname.herokuapp.com/>
をコールバックURLに指定し、Heroku上でプログラムを実行すると、認証に失敗？し、次の処理に進みません。

'''gather_keys_oauth2.py'''

[code]

    import cherrypy
            cherrypy.config.update({
            'server.socket_host': '0.0.0.0',
            'server.socket_port': int(os.environ.get('PORT', '5000')),
        })
    
        def __init__(self, client_id, client_secret,
                     redirect_uri='https://appname.herokuapp.com'):
    
[/code]

app.py

[code]

    server = gather_keys_oauth2.OAuth2Server(client_id, client_secret)
    server.browser_authorize()
    
[/code]

コンソールのメッセージ(Heroku上での実行。このメッセージの後、次の処理に移らない)

[code]

    [17/Apr/2017:16:44:13] ENGINE Listening for SIGTERM.
    [17/Apr/2017:16:44:13] ENGINE Listening for SIGHUP.
    [17/Apr/2017:16:44:13] ENGINE Listening for SIGUSR1.
    [17/Apr/2017:16:44:13] ENGINE Bus STARTING
    CherryPy Checker:
    The Application mounted at '' has an empty config.
    
    [17/Apr/2017:16:44:13] ENGINE Started monitor thread '_TimeoutMonitor'.
    [17/Apr/2017:16:44:13] ENGINE Started monitor thread 'Autoreloader'.
    [17/Apr/2017:16:44:13] ENGINE Serving on http://0.0.0.0:28452
    [17/Apr/2017:16:44:13] ENGINE Bus STARTED
    
[/code]

コンソールのメッセージ(ローカルでの実行。この後、次の処理に進む)

[code]

    [17/Apr/2017:12:18:52] ENGINE Listening for SIGTERM.
    [17/Apr/2017:12:18:52] ENGINE Listening for SIGUSR1.
    [17/Apr/2017:12:18:52] ENGINE Listening for SIGHUP.
    [17/Apr/2017:12:18:52] ENGINE Bus STARTING
    CherryPy Checker:
    The Application mounted at '' has an empty config.
    
    [17/Apr/2017:12:18:52] ENGINE Started monitor thread 'Autoreloader'.
    [17/Apr/2017:12:18:52] ENGINE Started monitor thread '_TimeoutMonitor'.
    [17/Apr/2017:12:18:52] ENGINE Serving on http://127.0.0.1:8080
    [17/Apr/2017:12:18:52] ENGINE Bus STARTED
    127.0.0.1 - - [17/Apr/2017:12:18:55] "GET /?code=認証コード HTTP/1.1" 200 122 "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30"
    127.0.0.1 - - [17/Apr/2017:12:18:55] "GET /apple-touch-icon-precomposed.png HTTP/1.1" 404 1385 "" "Safari/12603.1.30.0.34 CFNetwork/811.4.18 Darwin/16.5.0 (x86_64)"
    127.0.0.1 - - [17/Apr/2017:12:18:55] "GET /apple-touch-icon.png HTTP/1.1" 404 1361 "" "Safari/12603.1.30.0.34 CFNetwork/811.4.18 Darwin/16.5.0 (x86_64)"
    [17/Apr/2017:12:18:56] ENGINE Bus STOPPING
    [17/Apr/2017:12:19:01] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) shut down
    [17/Apr/2017:12:19:01] ENGINE Stopped thread '_TimeoutMonitor'.
    [17/Apr/2017:12:19:01] ENGINE Stopped thread 'Autoreloader'.
    [17/Apr/2017:12:19:01] ENGINE Bus STOPPED
    [17/Apr/2017:12:19:01] ENGINE Bus EXITING
    [17/Apr/2017:12:19:01] ENGINE Bus EXITED
    [17/Apr/2017:12:19:01] ENGINE Waiting for child threads to terminate...
    
[/code]


CC BY-SA 3.0
2017-04-17T07:53:57.233
34067
2017-04-17T07:53:57.233
18443
question
python heroku oauth
Heroku上のプログラムからのOAuth2認証