Keep Facebook Page Access Token valid while changing server

103 Views Asked by At

I've made a simple website for my personal usage using flask where I can post something to my facebook page. There is a textarea where I write text and then submit it. Then the server process the text and post it on that page using graph api and access token. It works well on my system. But when I deploy this project on live server the access token expired. If I put the token on access token debugger it says facebook removed access to the token duo session change.

I search about this on google (my bestfriend ;) but found nothing. I want to post on my page without expiring token while changing server. Or is there any alternative way to post on page?

Edit:

Here is the code I'm trying to post with...

import requests
from urllib.parse import quote_plus

acc_tk='EAA....MY_PAGE_ACCESS_TOKEN'
def post_fb(message):
    resp=requests.post(f"https://graph.facebook.com/v15.0/113023048137080/feed?message={quote_plus(message)}&access_token={acc_tk}")
    if resp.status_code==200:
        return True
    else:
        return False

When I create a new page access token and run this function, it returns true and the post is published on the page. But if I deploy this to live server the access token expires and then this function doesn't work any more even on local machine. If I debug this token this warning shows up~

enter image description here

1

There are 1 best solutions below

0
Shahriar On

After 1 day of debugging, I realized that the token get expired when I store token in a variable (like I showed in the question) and push it on github and then deploy it to render.com. So I managed to store token in my database and retrieve it when needed. And that's it! My code is working now.

But one thing I didn't understand that why my token get expired if I push it to github and deploy it on render.com... I found no reason about this.