Server Side OAuth Facebook Token Refresh

I have a ColdFusion web page that my server refreshes every x minutes. This script checks various channels (Facebook, YouTube and internal news) and builds the merged feed in chronological order. The Facebook part is just pulling data from our Facebook page. I can do this using the OAuth token provided when authorizing my app from our account.

token expires every couple of months or whatever I think. It takes quite a long time and I read that there is no way to authorize the application. However, I read all the time about these refresh tokens or something, but cannot figure out how they work.

I would like my script to try to get JSON data from Facebook, and if the token expires so often, re-request it, but it seems like just click on graphs.facebook.com/oauth/authorize the link doesn't work again because obviously , you need to be logged in for it to resolve something.

Either way, I can internally re-authorize or update my side of the token. This application for Facebook, site and Facebook users is completely internal. There used to be an RSS feed of facebook pages, but Facebook changes stuff all the time and I don't see it anymore.

All I really need is timeline / feed data for my Facebook page.

Any solutions or suggestions would be helpful.

ANSWER: . This is what I used to get content based data. Below takes a token, then uses the token to grab the feed data and places it in a structure. This may not be the most concise way, but it works.

<cfhttp url="https://graph.facebook.com/oauth/access_token?client_id=[CLIENTID]&client_secret=[CLIENTSECRET]&grant_type=client_credentials&redirect_uri=[URL] "   
        result="AccessHTTP" />
<cfset token = replace(AccessHTTP.Filecontent,"access_token=", "", "ALL")>

<cfhttp result="result" url="https://graph.facebook.com/[USERNAME]/posts?access_token=#token#" ></cfhttp>
<cfset Facebook = deserializeJSON(result.filecontent).data />

      

+3


source to share


1 answer


I just grab the token every time my page loads.

<cfhttp url="https://graph.facebook.com/oauth/access_token?client_id=your_client_id&client_secret=your_secret&grant_type=client_credentials" result="ThisHTTP" /> <cfset this.access_token = '#replace(ThisHTTP.Filecontent,"access_token=", "", "ALL")#'>



/// Run the code below using # this.access_token # whenever you need it .///

0


source







All Articles