Permalink
Browse files

Made it easier to bootstrap and run tests + interactive by allowing u…

…ser to specify access token in config

Summary: Made it easier to bootstrap and run tests + interactive by allowing user to specify access token in config

Test Plan: Define access_token in config
  • Loading branch information...
1 parent 143a4d9 commit 70569a6e96cc08d67c4aade1c22b107072e76f10 Evan Chen committed Nov 6, 2014
Showing with 23 additions and 16 deletions.
  1. +5 −7 README.md
  2. +2 −1 config.json.example
  3. +10 −5 facebookads/bootstrap.py
  4. +6 −3 facebookads/test/integration.py
View
@@ -82,16 +82,13 @@ The rest of the example code given will assume you have bootstrapped the api
into your program like the following sample app:
```python
-from facebookads.session import FacebookSession
from facebookads.api import FacebookAdsApi
from facebookads import objects
-my_app_id = '<Your app id>'
-my_app_secret = '<Your app secret>'
-my_access_token = '<This should be your access token>'
-my_session = FacebookSession(my_app_id, my_app_secret, my_access_token)
-my_api = FacebookAdsApi(my_session)
-FacebookAdsApi.set_default_api(my_api)
+my_app_id = '<APP_ID>'
+my_app_secret = '<APP_SECRET>'
+my_access_token = '<ACCESS_TOKEN>'
+FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
```
**NOTE**: We shall use the objects module throughout the rest of the tutorial.
@@ -322,6 +319,7 @@ details.
```
python -m facebookads.test.unit
python -m facebookads.test.integration <ACCESS_TOKEN>
+# Access token not required if it's defined in config.json
```
## Examples
View
@@ -2,5 +2,6 @@
"app_id": "<YOUR_APP_ID>",
"app_secret": "<YOUR_APP_SECRET>",
"act_id": "act_<YOUR_ACCOUNT_ID>",
- "page_id": "<YOUR_PAGE_ID>"
+ "page_id": "<YOUR_PAGE_ID>",
+ "access_token": "<ACCESS_TOKEN>"
}
View
@@ -9,12 +9,14 @@
from facebookads.exceptions import FacebookError
-def auth(access_token):
- if not hasattr(main, '__file__'):
- config_file = open('./config.json')
- config = json.load(config_file)
- config_file.close()
+config_file = open('./config.json')
+config = json.load(config_file)
+config_file.close()
+
+def auth(access_token=None):
+ if sys.__stdin__.isatty():
+ access_token = access_token or config['access_token']
FacebookAdsApi.init(
config['app_id'],
config['app_secret'],
@@ -29,3 +31,6 @@ def auth(access_token):
"## Or try using FacebookAdsApi.init()"
"\n"
)
+
+if config['app_id'] and config['app_secret'] and config['access_token']:
+ auth()
@@ -429,10 +429,13 @@ def runTest(self):
app_id = config['app_id']
app_secret = config['app_secret']
- if len(sys.argv) < 2:
- raise TypeError("Please provide the access token as an argument")
+ if 'access_token' in config:
+ access_token = config['access_token']
+ else:
+ if len(sys.argv) < 2:
+ raise TypeError("Please provide the access token as an argument")
- access_token = sys.argv.pop()
+ access_token = sys.argv.pop()
FacebookAdsTestCase.TEST_SESSION = session.FacebookSession(
app_id,

0 comments on commit 70569a6

Please sign in to comment.