PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] How to extend facebook access token in python

 June 29, 2022     facebook, facebook-graph-api, facebook-sdk-4.0, python-2.7     No comments   

Issue

I am using the Python facebook-sdk client library. I currently have a short-lived access token obtained from https://developers.facebook.com/tools/accesstoken/ that I copy the code from the site into my code for authentication.

       graph = facebook.GraphAPI(access_token)

This token however expires after 60-mins. I am looking to extend this to a 60 day-long lived token so that don't need to manually copy in new every time it expires. I can find numerous answers on how to do this in different formats, however not python (or at least not simply without log in page etc.).

[for reference, the code I will be using is only intended for my use, and as such, I am not looking to create a log in page. I just want to be able to extend the token I already have].


Solution

Not sure if this was available in python's FB API when the question was originally asked, but a neater approach to extend the expiry of the access token would be:

graph = facebook.GraphAPI(user_short_lived_token_from_client)
app_id = 'app_id' # Obtained from https://developers.facebook.com/
app_secret = 'app_secret' # Obtained from https://developers.facebook.com/

# Extend the expiration time of a valid OAuth access token.
extended_token = graph.extend_access_token(app_id, app_secret)
print extended_token #verify that it expires in 60 days


Answered By - uchamp
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing