81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
|
|
import os
|
|
import sys
|
|
import json
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.orm import sessionmaker
|
|
import garth
|
|
from garth.auth_tokens import OAuth1Token, OAuth2Token
|
|
|
|
# Setup DB connection
|
|
DATABASE_URL = "postgresql://postgres:password@db:5432/fitbit_garmin_sync"
|
|
engine = create_engine(DATABASE_URL)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
def debug_connection():
|
|
print(f"Garth version: {garth.__version__}")
|
|
print(f"Type of garth.client: {type(garth.client)}")
|
|
print(f"Content of garth.http.client: {garth.http.client}")
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
# Fetch tokens
|
|
result = db.execute(text("SELECT garth_oauth1_token, garth_oauth2_token FROM api_tokens WHERE token_type='garmin'"))
|
|
row = result.fetchone()
|
|
|
|
if not row:
|
|
print("No tokens found.")
|
|
return
|
|
|
|
oauth1_json = row[0]
|
|
oauth2_json = row[1]
|
|
|
|
print(f"Loaded OAuth1 JSON type: {type(oauth1_json)}")
|
|
|
|
oauth1_data = json.loads(oauth1_json)
|
|
oauth2_data = json.loads(oauth2_json)
|
|
|
|
print("Instantiating tokens...")
|
|
oauth1 = OAuth1Token(**oauth1_data)
|
|
oauth2 = OAuth2Token(**oauth2_data)
|
|
|
|
print(f"OAuth1Token object: {oauth1}")
|
|
|
|
# assign to garth.client
|
|
garth.client.oauth1_token = oauth1
|
|
garth.client.oauth2_token = oauth2
|
|
|
|
print("Tokens assigned.")
|
|
print(f"garth.client.oauth1_token type: {type(garth.client.oauth1_token)}")
|
|
|
|
# Try connectapi directly
|
|
print("Attempting garth.client.connectapi('/userprofile-service/socialProfile')...")
|
|
try:
|
|
profile_direct = garth.client.connectapi("/userprofile-service/socialProfile")
|
|
print("Direct connectapi success!")
|
|
print(f"Profile keys: {profile_direct.keys()}")
|
|
except Exception as e:
|
|
print(f"Direct connectapi failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
# Try via UserProfile.get()
|
|
print("Attempting garth.UserProfile.get()...")
|
|
try:
|
|
profile = garth.UserProfile.get()
|
|
print("UserProfile.get() success!")
|
|
except Exception as e:
|
|
print(f"UserProfile.get() failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
except Exception as e:
|
|
print(f"General error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
finally:
|
|
db.close()
|
|
|
|
if __name__ == "__main__":
|
|
debug_connection()
|