Home > Backend Development > PHP Tutorial > How Can I Extend Facebook Access Token Validity After the `offline_access` Permission Deprecation?

How Can I Extend Facebook Access Token Validity After the `offline_access` Permission Deprecation?

Linda Hamilton
Release: 2024-11-25 11:00:12
Original
466 people have browsed it

How Can I Extend Facebook Access Token Validity After the `offline_access` Permission Deprecation?

Extending Access Token Validity in the Absence of offline_access Permission

Since the deprecation of the offline_access permission in Facebook's authentication flow, extending access token validity has become a challenge. Despite documentation suggesting server-side OAuth-generated access tokens should have extended expiration, this is not the case.

To address this issue, a new function has been added to the base_facebook.php file. This function, getExtendedAccessToken(), allows developers to obtain a new access token that expires within 60 days.

Usage:

To utilize this function, simply add the following code to your base_facebook.php file and make a call to it:

public function getExtendedAccessToken(){
    // OAuth request to obtain extended access token
    $access_token_response = $this->_oauthRequest(
        $this->getUrl('graph', '/oauth/access_token'), array(
            'client_id' => $this->getAppId(),
            'client_secret' => $this->getAppSecret(),
            'grant_type' => 'fb_exchange_token',
            'fb_exchange_token' => $this->getAccessToken()
        )
    );
}
Copy after login

Important Note:

It's necessary to enable 'deprecate offline_access' in the advanced settings of the developer app for this function to work.

Updated SDK Function:

As of August 14th, 2012, the official Facebook PHP SDK has been updated. The function name has been changed to setExtendedAccessToken, and the SDK now stores the extended access token within persistent data rather than returning it. To retrieve the new access token, use the getAccessToken() function.

The above is the detailed content of How Can I Extend Facebook Access Token Validity After the `offline_access` Permission Deprecation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template