Skip to content

Commit 0b15a7f

Browse files
committed
load_pinterest_report_into_temp_dataset client_id, client_secret and refresh_token params
1 parent c1d35ab commit 0b15a7f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

bigfunctions/load/saas/load_pinterest_report_into_temp_dataset.yaml

+33-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ description: |
44
Download [Pinterest Custom Report](https://help.pinterest.com/en-gb/business/article/create-edit-and-review-custom-reports){ target='_blank' }
55
into `destination_table` inside a temporary dataset.
66
7+
To get the needed `client_id`, `client_secret` and `refresh_token` from Pinterest, read their documentation [here](https://developers.pinterest.com/docs/getting-started/connect-app/) and then [there](https://developers.pinterest.com/docs/getting-started/set-up-authentication-and-authorization/).
8+
9+
If you need help in getting thoses, you can get help on our [Slack](https://join.slack.com/t/unytics/shared_invite/zt-1gbv491mu-cs03EJbQ1fsHdQMcFN7E1Q).
10+
711
??? note "More on temporary datasets"
812
913
Each call to this function **creates a new temporary dataset** which:
@@ -18,7 +22,12 @@ arguments:
1822
type: int64
1923
- name: report_template_id
2024
type: int64
21-
- name: access_token
25+
- name: client_id
26+
type: string
27+
- name: client_secret
28+
type: string
29+
contains_secret: true
30+
- name: refresh_token
2231
type: string
2332
contains_secret: true
2433
- name: start_date
@@ -47,6 +56,29 @@ code: | #python
4756
4857
assert ad_account_id, 'invalid ad_account_id: it is null or empty'
4958
assert report_template_id, 'invalid report_template_id: it is null or empty'
59+
assert client_id, 'missing client_id'
60+
assert client_secret, 'missing client_secret'
61+
assert refresh_token, 'missing refresh_token'
62+
assert refresh_token.startswith('pina_'), 'invalid refresh_token'
63+
64+
def get_access_token():
65+
token_url = "https://api.pinterest.com/v5/oauth/token"
66+
credentials = f"{client_id}:{client_secret}"
67+
credentials_bytes = credentials.encode('utf-8')
68+
base64_credentials = base64.b64encode(credentials_bytes).decode('utf-8')
69+
headers = {
70+
"Authorization": f"Basic {base64_credentials}",
71+
"Content-Type": "application/x-www-form-urlencoded",
72+
}
73+
payload = {
74+
"grant_type": "refresh_token",
75+
"refresh_token": refresh_token,
76+
}
77+
response = requests.post(token_url, headers=headers, data=payload)
78+
data = response.json()
79+
return data['access_token']
80+
81+
access_token = get_access_token()
5082
5183
def request(method, url):
5284
headers = {

0 commit comments

Comments
 (0)