Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -6,20 +6,39 @@ import requests
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
VERIFY_TOKEN = "my_secure_token"
|
| 9 |
-
PAGE_ACCESS_TOKEN = "
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@app.get("/webhook")
|
| 12 |
async def verify_webhook(request: Request):
|
| 13 |
params = request.query_params
|
|
|
|
| 14 |
mode = params.get("hub.mode")
|
| 15 |
token = params.get("hub.verify_token")
|
| 16 |
challenge = params.get("hub.challenge")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if mode == "subscribe" and token == VERIFY_TOKEN:
|
| 19 |
return PlainTextResponse(content=challenge)
|
| 20 |
return PlainTextResponse(content="Verification failed", status_code=403)
|
| 21 |
|
| 22 |
-
|
| 23 |
@app.post("/webhook")
|
| 24 |
async def receive_webhook(request: Request):
|
| 25 |
payload = await request.json()
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
VERIFY_TOKEN = "my_secure_token"
|
| 9 |
+
PAGE_ACCESS_TOKEN = "EAAJGMsgQEhMBO0FxGBA1ZBKVIM6HmYYDK9stTrz4XjgN7PDOnkgH3g5WScFZBIVp6ZBXEN4rEsRuelZChxDnELXfojjkXyw9WUcZBYevkinXRIYsdjGZAGQ6QK2MDmnlX6mW4tD4uKzcpKxaaRDzPFouM51Vn6Yx5tatqYJyPBd39z1391QtEzTWWp8CS1BXuBdAJ078l4QF1uQ1ybQ4k4eksZD" # Replace after exchange
|
| 10 |
+
APP_ID = "640133872226835"
|
| 11 |
+
APP_SECRET = "01602f51d9aa49953064fda7c507ed7c" # Replace with your actual secret
|
| 12 |
+
REDIRECT_URI = "https://mr-help-binrushd-meta-authenticator.hf.space/webhook"
|
| 13 |
|
| 14 |
@app.get("/webhook")
|
| 15 |
async def verify_webhook(request: Request):
|
| 16 |
params = request.query_params
|
| 17 |
+
code = params.get("code")
|
| 18 |
mode = params.get("hub.mode")
|
| 19 |
token = params.get("hub.verify_token")
|
| 20 |
challenge = params.get("hub.challenge")
|
| 21 |
|
| 22 |
+
# OAuth2 token exchange logic
|
| 23 |
+
if code:
|
| 24 |
+
print(f"🔑 Received code: {code}")
|
| 25 |
+
token_url = "https://graph.facebook.com/v22.0/oauth/access_token"
|
| 26 |
+
token_params = {
|
| 27 |
+
"client_id": APP_ID,
|
| 28 |
+
"redirect_uri": REDIRECT_URI,
|
| 29 |
+
"client_secret": APP_SECRET,
|
| 30 |
+
"code": code
|
| 31 |
+
}
|
| 32 |
+
response = requests.get(token_url, params=token_params)
|
| 33 |
+
print("🎟️ Token Exchange Response:")
|
| 34 |
+
print(response.json())
|
| 35 |
+
return PlainTextResponse("Token exchange completed")
|
| 36 |
+
|
| 37 |
+
# Webhook verification logic
|
| 38 |
if mode == "subscribe" and token == VERIFY_TOKEN:
|
| 39 |
return PlainTextResponse(content=challenge)
|
| 40 |
return PlainTextResponse(content="Verification failed", status_code=403)
|
| 41 |
|
|
|
|
| 42 |
@app.post("/webhook")
|
| 43 |
async def receive_webhook(request: Request):
|
| 44 |
payload = await request.json()
|