-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathget-integrations
More file actions
executable file
·68 lines (54 loc) · 2.12 KB
/
Copy pathget-integrations
File metadata and controls
executable file
·68 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
from __future__ import print_function
import json
from requests_oauthlib import OAuth2Session
with open('credentials.json', 'rt') as f:
credentials = json.load(f)
TOKEN_URL = "https://auth.aweber.com/oauth2/token"
client_id = credentials['client_id']
client_secret = credentials['client_secret']
token = credentials['token']
extra = {
'client_id': client_id,
'client_secret': client_secret,
'token': token
}
def token_updater(token):
with open('credentials.json', 'wt') as creds_file:
json.dump(
{
'client_id': client_id,
'client_secret': client_secret,
'token': token
}, creds_file)
print('Token was refreshed.\n'
'Updated credentials.json with your new credentials')
session = OAuth2Session(client_id=credentials['client_id'],
token=credentials['token'],
auto_refresh_url=TOKEN_URL,
auto_refresh_kwargs=extra,
token_updater=token_updater)
def get_collection(url):
collection = []
while url:
response = session.get(url)
response.raise_for_status()
body = response.json()
collection.extend(body['entries'])
# if there is a next link, there are more pages to retrieve
next_link = body.get('next_collection_link')
url = next_link if next_link else None
return collection
# get all of the accounts
account_url = 'https://api.aweber.com/1.0/accounts'
accounts = get_collection(account_url)
# get all sharing integration uri's for twitter and facebook
# these are used to create a broadcast that will post to twitter or facebook
# see broadcast example here: https://github.com/aweber/public-api-examples/
# blob/master/python/create-schedule-broadcast
integrations = get_collection(accounts[0]['integrations_collection_link'])
print('Integrations:')
for integration in integrations:
if integration['service_name'].lower() in ('twitter', 'facebook'):
print(integration['service_name'], integration['login'],
integration['self_link'])