This class is designed for interacting with the Facebook Graph API
| 24 | |
| 25 | |
| 26 | class FacebookConnector(object): |
| 27 | """ |
| 28 | This class is designed for interacting with the Facebook Graph API |
| 29 | """ |
| 30 | |
| 31 | fb_config_file = "connector.config" |
| 32 | KEY = None |
| 33 | TOKEN = None |
| 34 | BASE_URL = "https://graph.facebook.com/" |
| 35 | VERSION = "v2.11" |
| 36 | _logger = None |
| 37 | |
| 38 | def _log(self): |
| 39 | """ |
| 40 | Get the log |
| 41 | """ |
| 42 | return logging.getLogger(__name__) |
| 43 | |
| 44 | def _init_facebook(self, config): |
| 45 | self.BASE_URL = ConnectorUtil.get_config_setting( |
| 46 | self._logger, config, "Facebook", "fb.url" |
| 47 | ) |
| 48 | self.KEY = ConnectorUtil.get_config_setting( |
| 49 | self._logger, config, "Facebook", "fb.app_id" |
| 50 | ) |
| 51 | self.TOKEN = ConnectorUtil.get_config_setting( |
| 52 | self._logger, config, "Facebook", "fb.app_secret" |
| 53 | ) |
| 54 | self.VERSION = ConnectorUtil.get_config_setting( |
| 55 | self._logger, config, "Facebook", "fb.graph_version" |
| 56 | ) |
| 57 | |
| 58 | def __init__(self, config_file="", log_level=None): |
| 59 | if config_file != "": |
| 60 | self.fb_config_file = config_file |
| 61 | |
| 62 | self._logger = self._log() |
| 63 | if log_level is not None: |
| 64 | self._logger.setLevel(log_level) |
| 65 | |
| 66 | config = configparser.ConfigParser() |
| 67 | list = config.read(self.fb_config_file) |
| 68 | if len(list) == 0: |
| 69 | self._logger.error("Error: Could not find the config file") |
| 70 | exit(1) |
| 71 | |
| 72 | self._init_facebook(config) |
| 73 | |
| 74 | def get_facebook_access_token(self): |
| 75 | """ |
| 76 | Fetch the Facebook oauth access token. |
| 77 | This is not completely necessary since app_id|app_secret also works as an access token. |
| 78 | Exit if there is an error |
| 79 | """ |
| 80 | try: |
| 81 | req = requests.get( |
| 82 | self.BASE_URL |
| 83 | + self.VERSION |
nothing calls this directly
no outgoing calls
no test coverage detected