Skip to content

Commit

Permalink
simplify config by switching the authentication to app access tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Dziedziul committed Dec 25, 2017
1 parent 08ffa9d commit ef49524
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Create config file:
Set paramaters in `matterbook.yml`:
```
facebook:
access_token: SGEgaGEgaGEhIENoY2lhxYJiecWbIDpQ # Obtained from https://developers.facebook.com/tools/explorer
app_id: 123 # Obtained from https://developers.facebook.com/apps
app_secret: 123 # Obtained from https://developers.facebook.com/apps
Expand Down
24 changes: 3 additions & 21 deletions matterbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@ def main():
time.sleep(10)



def load_config():
with open(CONFIG_FILE, 'r') as f:
config = yaml.safe_load(f)
log.debug("Config loaded")
return config


def save_config(config):
with open(CONFIG_FILE, 'w') as f:
yaml.safe_dump(config, f, default_flow_style=False)
log.debug("Config saved")
return config


def check_posts(graph, config):
mm_config = config['mattermost']
integrations = config['integrations']
Expand Down Expand Up @@ -106,22 +98,12 @@ def load_last_saved_post(integration_id):


def get_graph_api(config):
extended_token = get_extended_token(config)
graph = facebook.GraphAPI(access_token=extended_token, version=FB_API_VERSION)
return graph


def get_extended_token(config):
fb_config = config['facebook']
access_token = fb_config['access_token']
app_id = fb_config['app_id']
app_secret = fb_config['app_secret']
graph = facebook.GraphAPI(access_token=access_token, version=FB_API_VERSION)
extended_token_data = graph.extend_access_token(app_id, app_secret)
extended_token = extended_token_data['access_token']
fb_config['access_token'] = extended_token
save_config(config)
return extended_token
token = facebook.GraphAPI().get_app_access_token(app_id, app_secret)
graph = facebook.GraphAPI(access_token=token, version=FB_API_VERSION)
return graph


def install_interrupt_handler():
Expand Down
1 change: 0 additions & 1 deletion matterbook.yml.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
facebook:
access_token: SGEgaGEgaGEhIENoY2lhxYJiecWbIDpQ # Obtained from https://developers.facebook.com/tools/explorer
app_id: 123 # Obtained from https://developers.facebook.com/apps
app_secret: 123 # Obtained from https://developers.facebook.com/apps
integrations:
Expand Down

0 comments on commit ef49524

Please sign in to comment.