-
-
Save TheMuellenator/974c39779ec516c4c60e918c001e48ba to your computer and use it in GitHub Desktop.
Day 38 L291 - Solution: Authenticate Your Sheety API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #No Authentication | |
| sheet_response = requests.post(sheet_endpoint, json=sheet_inputs) | |
| #Basic Authentication | |
| sheet_response = requests.post( | |
| sheet_endpoint, | |
| json=sheet_inputs, | |
| auth=( | |
| YOUR USERNAME, | |
| YOUR PASSWORD, | |
| ) | |
| ) | |
| #Bearer Token Authentication | |
| bearer_headers = { | |
| "Authorization": f"Bearer {YOUR TOKEN}" | |
| } | |
| sheet_response = requests.post( | |
| sheet_endpoint, | |
| json=sheet_inputs, | |
| headers=bearer_headers | |
| ) |
{'sheet1': {'id': 3}} i get this output but my spreadsheet didn't change?????
for exercise in result["exercises"]:
sheet_inputs = {
"sheet1": {
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason, the info doesn't get populated into google sheets. I have checked that the permissions are given to Sheety on my gmail account, and the data is nested in the API root.
import requests
from datetime import datetime
API_KEY = "nix_live_igDg82h4BmwMowKrwnL0TAzILSNKwXzG"
API_ID = "app_eef0ff9273e147b6859e10db"
endpoint = "https://app.100daysofpython.dev/v1/nutrition/natural/exercise"
sheety_token = "Bearer 48fnef@49%)#)@Ejdnce03r38u3rf"
sheety_endpoint = "https://api.sheety.co/121544da6b8eef4be1a71d43d91442d3/ramaWorkouts/workouts"
headers = {
"Content-Type": "application/json",
"x-app-id": API_ID,
"x-app-key": API_KEY
}
workout_data = {
"query":"ran 24km",
"weight_kg":72.3,
"height_cm":171,
"age": 33,
"gender":"male"
}
workout_info = requests.post(url = endpoint, json = workout_data, headers= headers)
result = workout_info.json()
headers = {
"Authorization":sheety_token
}
workout_date = datetime.today().strftime("%d/%m/%Y")
workout_time = datetime.now().strftime("%H:%M:%S")
for exercise in result['exercises']: