I have managed to post to Facebook Page via API (C#), but when administrator of the page logs out, the following error occurs:
\"(OAuthException - #190) Error valida
The method below worked for me, if you are using 4.x Facebook SDK:
//Class for Generating the Long Lived Token
namespace App\Lib;
use Facebook\FacebookApp;
use Facebook\FacebookClient;
use Facebook\Authentication\OAuth2Client;
class FacebookLongLivedTokenGenerator
{
public $longLivedTokenGenerated = false;
public function generateFacebookLongLivedToken($appId, $appSecret, $oldToken)
{
//request new access token
$oauth2Fb = new OAuth2Client(new FacebookApp($appId, $appSecret), new FacebookClient());
$longLivedToken = $oauth2Fb->getLongLivedAccessToken($oldToken);
if ($longLivedToken) {
$this->longLivedTokenGenerated = true;
$this->userAccessToken = $longLivedToken;
}
return trim($this->userAccessToken);
}
}
You can consume the above class this way:
$longToken = new FacebookLongLivedTokenGenerator();
echo $longToken->generateFacebookLongLivedToken($appId, $appSecret, $oldUserAccessToken);